忽略这个:
我在 Onload 方法中重新绑定(bind)网格。
我有一个带有一些文本框的 GridView ,我必须将它们包装在 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 的情况下获取文本框的值。我需要更新面板,因为行数和日期取决于另一个用户控件中的另一个变量。
最佳答案
根据我的理解,您应该为更新面板使用触发器,如下所示。
<asp:UpdatePanel ...>
<ContentTemplate>
...
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
希望这对您有所帮助!
关于c# - UpdatePanel 中的 GridView - 在单击按钮时获取更新的文本框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7679706/