我想在C#ASP .NET中获得Gridview页脚行的Textbox的值

时间:2013-01-31 11:13:34

标签: c# asp.net .net

  

可能重复:
  How to find the value of textbox from the footer row of gridview in C# ASP.NET

我想在C#ASP .NET中获取Gridview页脚行的Textbox值,但textbox的返回值为null或为空。

<asp:GridView ID="GridView1" runat="server" Width="1214px"       
        AutoGenerateColumns="False" ShowFooter="true" 
        OnRowDataBound="GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand">
        <Columns>
        <asp:TemplateField HeaderText="Update">
            <ItemTemplate>
                <asp:LinkButton ID="lbtn_Update" runat="server" Text="Update"/>
                <asp:LinkButton ID="lbtn_Delete" runat="server" Text="Delete"/>
            </ItemTemplate>
            <FooterTemplate>
               <asp:LinkButton ID="lbtn_Delete" runat="server"CommandArgument="AddNew" Text="Insert"/>
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Student ID">
            <EditItemTemplate>
                <asp:Label ID="lblEditSID" runat="server" Text='<%#Eval("sid")%>' />
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="lblSID" runat="server" Text='<%#Eval("sid")%>' />
            </ItemTemplate>
            <FooterTemplate>
                <asp:TextBox ID="txtSID" runat="server" MaxLength="50"/>
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Student Name">
            <EditItemTemplate>
               <asp:Label ID="lblEditSName" runat="server" Text='<%#Eval("sname")%>'/>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="lblSName" runat="server" Text='<%#Eval("sname")%>' />
            </ItemTemplate>
            <FooterTemplate>
                <asp:TextBox ID="txtSName" runat="server"/>
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Student Mobile No">
            <EditItemTemplate>
               <asp:TextBox ID="txtEditMobile" runat="server" Text='<%#Eval("smno")%>'/>                 
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="lblMobile" runat="server" Text='<%#Eval("smno")%>' />
            </ItemTemplate>
            <FooterTemplate>
                <asp:TextBox ID="txtMobile" runat="server" />
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Student Email-ID">
            <EditItemTemplate>
          <asp:TextBox ID="txtEditEmail" runat="server" Text='<%#Eval("mailid")%>'/> 
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="lblEmail" runat="server" Text='<%#Eval("mailid")%>' />
            </ItemTemplate>
            <FooterTemplate>
                <asp:TextBox ID="txtEmail" runat="server" />
            </FooterTemplate>
            </asp:TemplateField>       
        </Columns>
    </asp:GridView>

这是代码背后的代码,我想在C#ASP .NET中获取Gridview页脚行的文本框的值,但是文本框的reurn值为null或为空

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {
    if (e.CommandArgument.Equals("AddNew")) {
        GridView test=(GridView)sender;
        TextBox txtSid = (TextBox)(test.FooterRow.FindControl("txtSID"));
        TextBox txtName = (TextBox)(GridView1.FooterRow.FindControl("txtSName"));
        TextBox txtMobile = (TextBox)(GridView1.FooterRow.FindControl("txtMobile"));
        TextBox txtEmail = ((TextBox)GridView1.FooterRow.FindControl("txtEmail"));            
        string strSid =txtSid.Text;
        string strName = txtName.Text;
        string strMobile = txtMobile.Text;
        string strEmail = txtEmail.Text;
     }
}

当我在文本框中输入值时,Textxtbox值为null或空字符串strName,其他字符串为空。

0 个答案:

没有答案