c# - UpdatePanel 中的 GridView - 在单击按钮时获取更新的文本框值

标签 c# asp.net gridview updatepanel

忽略这个:

我在 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/

相关文章:

asp.net - ASP.NET session 对象中的 Entity Framework 对象上下文?

c# - 使用 linq 或 subsonic 计算距离

android - Gridview——点击图片在Viewpager中查看图片

c# - 如何在不将图片保存到硬盘的情况下在 gridview 行中显示图片?

javascript - 如何将列表从 C# Angular 传递到 Angular Controller ?

c# - 如何从数组中获取所有可能的组合?

c# - 如何将 pinvoke 用于指向 C# 的 C 结构数组指针

asp.net - 系统未授权访问异常 : Access to the path is denied VS2013

c# - MVP 和多个用户控件

android - 删除 GridView 上的 FadingEdge。安卓 hive