【发布时间】:2011-06-23 20:36:39
【问题描述】:
我正在开发一个 ASP.NET/C# 项目,并且有一个 GridView 控件。其中一列是一个 TemplateField/ItemTemplate,里面有一个 ImageButton。在 OnClick 事件期间,我使面板可见。使用常规 ImageButton 执行此操作时,页面会重新加载并且面板可见。这不会发生在 GridView 内的 ImageButton 上。有谁知道我是怎么做到的,或者为什么会这样?
感谢您的宝贵时间,如果您有任何问题,请告诉我。
这是相关的asp定义
<asp:TemplateField ItemStyle-Width="90px" ItemStyle-VerticalAlign ="Bottom" ItemStyle-HorizontalAlign ="Center" HeaderText="Add Alias">
<HeaderStyle Font-Bold="True" Font-Size="11px" VerticalAlign="Bottom"/>
<ItemTemplate>
<asp:ImageButton ID ="btnAddAliasHeader" runat="server" ImageUrl="~/img/AddAlias.gif" onclick="btnAddAlias_Click" />
</ItemTemplate>
</asp:TemplateField>
这是 OnClick 函数的 C#。
protected void btnAddAlias_Click(object sender, EventArgs e)
{
ImageButton btnAddAlias = (ImageButton)sender;
GridViewRow row = (GridViewRow)btnAddAlias.Parent.Parent;
int rowIndex = row.RowIndex;
lblSelectedCity.Text = gvResults.Rows[rowIndex].Cells[0].Text;
lblSelectedCountry.Text = ddlCountry.Text;
pnlAddAlias.Visible = true;
}
我添加了 OnRowCommand 事件并使面板在那里可见,但它仍然不显示。我认为这可能与回发有关,因为如果我然后单击 gridview 外部的按钮,则在重新加载时,gridview 内部按钮的面板显示正常。
编辑:我是个白痴,忽略了所有这些都发生在更新面板中。
【问题讨论】:
-
GridView和Panel在同一个UpdatePanel内吗?
标签: c# asp.net gridview imagebutton