【发布时间】:2011-10-06 19:51:26
【问题描述】:
忽略这个:
我在 Onload 方法中重新绑定网格。
我有一个带有一些文本框的网格视图,我必须将它们包装在 UpdatePanel 控件中。所以它看起来像这样:
<asp:UpdatePanel ID="upDistribution" runat="server" OnLoad="upDistribution_OnLoad">
<ContentTemplate>
<asp:GridView ID="gvDistributions" runat="server" AutoGenerateColumns="false"
OnRowDataBound="gvDistributions_RowDataBound"
CssClass="TallCells ContrastTable MaxWidth LeftHeaders"
GridLines="Both" ShowFooter="True" style="">
<RowStyle HorizontalAlign="Left" />
<EmptyDataTemplate>
No pricing history data found.
</EmptyDataTemplate>
<Columns>
<asp:TemplateField HeaderText="PriceA">
<ItemTemplate>
<asp:TextBox ID="txtPriceA" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DistPrice">
<ItemTemplate>
<asp:TextBox ID="txtDistPrice" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
当我想获取为 txtboxes 输入的值时,有一个“保存”按钮。如果 GV 周围没有 UpdatePanel,我可以轻松获取 txtbox 值,例如:
((TextBox)gvDistributions.Rows[0].Cells[0].FindControl("txtPriceA")).Text
但是,当 GridView 被 UpdatePanel 包裹时,上述语句返回页面加载时设置的值。
如何在不去掉 updatePanel 的情况下获取文本框的值。我需要更新面板,因为行数和日期取决于另一个用户控件中的另一个变量。
【问题讨论】:
-
能否把hte按钮放到更新面板中,并使用脚本管理器将按钮注册为回发控件(假设您需要按钮进行回发)?
-
@JamesJohnson 不,我不能。
-
嗯...我的想法可能在这里倒退,但尝试在代码隐藏中添加
ScriptManager.GetCurrent().RegisterPostBackControl(txtDistPrice);? -
我们应该在这里忽略什么?您找到问题的答案了吗?如果是这样,请将其作为答案发布并标记为已接受。
标签: c# asp.net gridview updatepanel