c# - 在 C# 中禁用寻呼机模板上的图像按钮

标签 c# mysql asp.net

我在 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 上的所有内容设置为 visible 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: The name 'ImageButton1' does not exist in the current context.

你能帮我找出问题吗?

提前致谢。

最佳答案

您必须使用方法FindControl() 来确定控件

ImageButton btn =  (ImageButton)gvProducts.BottomPagerRow.FindControl("ImageButton1");
btn.Visible = false;

关于c# - 在 C# 中禁用寻呼机模板上的图像按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35935122/

相关文章:

C# 使用递归查找数组中数字的索引

asp.net - 在 asp.net(vb) 中控制 ajax 工具包自动完成的高度

asp.net - Visual Studio 中 Web API 和 Azure API APP 的区别

asp.net - 在 Visual Studio 2015 社区中看不到 "Create deploy package as a zip file"选项

c# - 无需配对即可在 Windows10 UWP 中查找蓝牙 Mac 地址

c# - 奇数/偶数 datagridview 行背景色

c# - 如何复制 C# 3D 锯齿状数组

mysql - Rails 在 Mac 上采用错误的 mysql 路径

php - sql查询的最佳字符集编码是什么?

c# - 从数据库中检索更新的数据