【发布时间】:2014-05-06 13:42:45
【问题描述】:
我有一个gridview,里面有下面的代码。
<asp:TemplateField HeaderText="Header 3">
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<!-- only your content that needs refreshing goes here -->
<asp:Button ID="ButtonAdd" runat="server" Text="Add New Row"
onclick="ButtonAdd_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ButtonAdd" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</FooterTemplate>
</asp:TemplateField>
我添加了更新面板,因为当我单击 ButtonAdd 时,gridview 中的按钮数据已被删除。但是在我添加下面的代码按钮后,单击事件不会触发。请提出解决方案。
【问题讨论】:
-
如果我是你,我会重新考虑整个解决方案。 GridViews 不能很好地与 UpdatePanels 配合使用。 UpdatePanels 不能很好地处理任何东西,而且 GridViews 在客户端比普通的 HTML 表格更难处理。您是否考虑过弹出一个对话框来获取新行的值,然后用新数据更新数据源,然后重新绑定 GridView,而不是向 GridView 添加一行?
-
如果您删除整个
<Triggers>部分会发生什么。按钮已经在 UpdatePanel 内,所以不需要 -
你为什么用
UpdatePanel来代替Button? -
如果我删除
,则完全没有变化。我需要更新面板以防止单击按钮时数据丢失,它在 gridview 内。