如何在footerrow中获取texbox的更新值 [英] How do I get the update value of a texbox in a footerrow

查看:116
本文介绍了如何在footerrow中获取texbox的更新值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于我在网格视图中有这个对象:



given that I have this object in my grid view:

asp:TemplateField HeaderText="Display Text" SortExpression="DisplayText">
        <ItemTemplate><%# Eval("DisplayText") %></ItemTemplate>
        <EditItemTemplate>
           <asp:TextBox ID="txtDisplayText" Text='<%# Eval("DisplayText") %>' runat="server"></asp:TextBox>
        </EditItemTemplate>
        <FooterTemplate>
             <asp:TextBox ID="txtDisplayText" Text="xxx" runat="server"></asp:TextBox>
        </FooterTemplate>
</asp:TemplateField>





当我在txtDisplayText中输入一个值时,我看不到我输入的内容OnRowCommand事件被执行。相反,我看到在aspx文件中为txtDisplayText(xxx)定义的文本。

我错过了什么?



我尝试过:



摆弄viewstate;搜索这个网站; Google



When I type a value into the txtDisplayText I do not see what I typed when the event OnRowCommand is executed. Rather I see the text defined in the aspx file for txtDisplayText("xxx").
What have I missed?

What I have tried:

fiddling with viewstate; searching this site; Google

推荐答案

正如评论中所讨论的,问题是由于在每次加载页面时绑定网格而未检查 IsPostBack 属性优先。



每次绑定网格时,它都会丢弃用户输入的任何内容,并根据标记重新创建整个网格控制树和数据。



而不是:
As discussed in the comments, the problem is caused by binding the grid on every page load without checking the IsPostBack property first.

Every time you bind the grid, it throws away anything that the user has typed, and recreates the entire grid control tree based on the markup and the data.

Instead of:
protected void Page_Load(object sender, EventArgs e)
{
    BindGrid();
}



使用:


Use:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        BindGrid();
    }
}


这篇关于如何在footerrow中获取texbox的更新值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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