我无法从GridView控件的页脚行获取文本框的值 [英] I can't get the value of textbox from the footer row of gridview

查看:108
本文介绍了我无法从GridView控件的页脚行获取文本框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从GridView控件的页脚行获取文本框的值

 < ASP:GridView控件ID =GridView1=服务器WIDTH =1214px
            的AutoGenerateColumns =假ShowFooter =真
 OnRowCommand =GridView1_RowCommand
  <柱体和GT;
 < ASP:的TemplateField的HeaderText =插入>
            < / ASP:的TemplateField>
            < ASP:的TemplateField的HeaderText =学生姓名>
            <&EditItemTemplate的GT;
               < ASP:标签ID =lblEditSName=服务器文本='<%#的eval(SNAME)%>/>
            < / EditItemTemplate中>
            <&ItemTemplate中GT;
                < ASP:标签ID =lblSName=服务器文本='<%#的eval(SNAME)%>' />
            < / ItemTemplate中>
            < FooterTemplate>
                < ASP:文本框ID =txtSName=服务器/>
            < / FooterTemplate>
            < / ASP:的TemplateField>
            < /专栏>
        < / ASP:GridView的>

和code后面的是........
我无法从GridView控件的页脚行获取文本框的值

 保护无效GridView1_RowCommand(对象发件人,GridViewCommandEventArgs E)
{
    如果(e.CommandName ==(的AddNew))
    {
        文本框txtName的=(文本框)GridView1.FooterRow.FindControl(txtSName);
字符串则strName = txtName.Text; //则strName是空的,而我M进入数据到文本框txtSName
     }


解决方案

发布此评论,以帮助其他人谁可能会遇到同样的问题。结果

请确保电网不上后再次加载回来。结果

在页面加载code应该是这样的结果。

 如果(!的IsPostBack)
{
  LoadGrid();
}

i can't get the value of textbox from the footer row of gridview

    <asp:GridView ID="GridView1" runat="server" Width="1214px"       
            AutoGenerateColumns="False" ShowFooter="true" 
 OnRowCommand="GridView1_RowCommand"                                  
  <Columns>
 <asp:TemplateField HeaderText="Insert">
            </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>
            </Columns>
        </asp:GridView>

and the code behind is........ i can't get the value of textbox from the footer row of gridview

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName==("AddNew"))
    {
        TextBox txtName =(TextBox) GridView1.FooterRow.FindControl("txtSName");
string strName=txtName.Text;   //strName is Empty while i m enters data into the  textbox txtSName
     }

解决方案

Posting this comment to help others who may encounter the same issue.

Make sure the grid is not loading again on post back.

code in the page load should look like this

if (!IsPostBack)
{
  LoadGrid();
}

这篇关于我无法从GridView控件的页脚行获取文本框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆