在c#中禁用寻呼机模板上的图像按钮(Disable image button on Pager Template in c#)
我在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:当前上下文中不存在名称“ImageButton1”。
你能帮我解决一下这个问题吗?
提前致谢。
I work in ASP.NET c# and MySQL database.
In my gridView I have added this code pagination.
<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" />Now I need to set as visible false all the content on PagerTemplate when is activate :
protected void btnAdd_Click(object sender, ImageClickEventArgs e) { gvProducts.ShowFooter = true; btnAdd.Visible = false; BindData(); }I have tried with :
protected void btnAdd_Click(object sender, ImageClickEventArgs e) { gvProducts.ShowFooter = true; btnAdd.Visible = false; ImageButton1.Visible = false; BindData(); }But I have error :
CS0103: The name 'ImageButton1' does not exist in the current context.
Can you please help me figure out the problem?
Thanks in advance.
最满意答案
你必须使用FindControl()方法来确定Control
ImageButton btn = (ImageButton)gvProducts.BottomPagerRow.FindControl("ImageButton1"); btn.Visible = false;you have to use the method FindControl() to determine the Control
ImageButton btn = (ImageButton)gvProducts.BottomPagerRow.FindControl("ImageButton1"); btn.Visible = false;更多推荐
发布评论