IGNORE THIS:
我正在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>
有一个按钮"保存"当我想得到输入的文本框的值。如果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>
希望这有帮助!!
使用TextBox
的AutoPostBack
属性集True
<asp:TextBox ID="txtPriceA" runat="server" AutoPostBack="True"/>
我在onLoadMethod中重新绑定gridview