如何从C#ASP.NET的gridview页脚行中找到文本框的值

时间:2022-12-02 14:03:53
        <FooterTemplate>
            <asp:TextBox ID="txtSName" runat="server" Text=""/>
        </FooterTemplate>

and the codebehind Code is as:

代码隐藏代码如下:

TextBox txtName = (TextBox)(GridView1.FooterRow.FindControl("txtSName"));
string aa=txtName.Text;

Everytime aa is null.

每次aa为空。

this code i m putting into the following:

我将这段代码放入以下内容中:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
}  

Please help me..........

请帮帮我..........

2 个解决方案

#1


1  

Try This code it might work:

试试这段代码它可能有效:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            TextBox txtName = GridView1.FooterRow.FindControl("txtSName") as TextBox;
            string aa = txtName.Text;
        }

#2


0  

Try this :

尝试这个 :

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
     TextBox txtName = (TextBox)e.Item.FindControl("txtSName");
} 

Let me know if it is working. Are you using this to add/update the record?

如果有效,请告诉我。您是否使用此添加/更新记录?

#1


1  

Try This code it might work:

试试这段代码它可能有效:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            TextBox txtName = GridView1.FooterRow.FindControl("txtSName") as TextBox;
            string aa = txtName.Text;
        }

#2


0  

Try this :

尝试这个 :

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
     TextBox txtName = (TextBox)e.Item.FindControl("txtSName");
} 

Let me know if it is working. Are you using this to add/update the record?

如果有效,请告诉我。您是否使用此添加/更新记录?