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

时间:2013-01-31 04:56:41

标签: c# asp.net

        <FooterTemplate>
            <asp:TextBox ID="txtSName" runat="server" Text=""/>
        </FooterTemplate>

和代码隐藏代码如下:

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

每次aa都是null

此代码我将进行以下操作:

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

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

2 个答案:

答案 0 :(得分:1)

尝试此代码可能有效:

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

答案 1 :(得分:0)

试试这个:

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

让我知道它是否有效。您是否将此用于add/update记录?