我在ASP.NET c#和MySQL数据库中工作。
在我的gridView中,我添加了此代码分页。
<PagerTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="/Images/bot_back_1.gif"
CommandArgument="First" CommandName="Page" Visible="true" />
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="/Images/bot_back.gif"
CommandArgument="Prev" CommandName="Page" Visible="true" />
Page
<asp:DropDownList ID="ddlPages" runat="server" AutoPostBack="True" CssClass="ddl_Class"
OnSelectedIndexChanged="ddlPages_SelectedIndexChanged" Visible="true">
</asp:DropDownList>
of
<asp:Label ID="lblPageCount" runat="server"></asp:Label>
<asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="/Images/bot_next.gif"
CommandArgument="Next" CommandName="Page" Visible="true" />
<asp:ImageButton ID="ImageButton4" runat="server" ImageUrl="/Images/bot_next_1.gif"
CommandArgument="Last" CommandName="Page" Visible="true" />
</PagerTemplate>
</asp:GridView>
<asp:ImageButton ID="btnAdd" runat="server" Visible="true" OnClick="btnAdd_Click" ImageUrl="/Images/Add_button.gif" />
现在我需要在激活时将PagerTemplate上的所有内容设置为可见false:
protected void btnAdd_Click(object sender, ImageClickEventArgs e)
{
gvProducts.ShowFooter = true;
btnAdd.Visible = false;
BindData();
}
我尝试过:
protected void btnAdd_Click(object sender, ImageClickEventArgs e)
{
gvProducts.ShowFooter = true;
btnAdd.Visible = false;
ImageButton1.Visible = false;
BindData();
}
但我有错误:
CS0103:名称&#39; ImageButton1&#39;在当前背景下不存在。
你能帮我解决一下这个问题吗?
提前致谢。
答案 0 :(得分:3)
您必须使用方法FindControl()
来确定控件
ImageButton btn = (ImageButton)gvProducts.BottomPagerRow.FindControl("ImageButton1");
btn.Visible = false;