图像按钮隐藏和隐藏 [英] Image button hide and un-hide

查看:77
本文介绍了图像按钮隐藏和隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网格视图中有一个名为StopImageButton和StartImageButton的图像按钮

I have a image button in my gridview that is named StopImageButton and StartImageButton

<asp:TemplateField HeaderText="Stop">
    <ItemTemplate>
         <asp:ImageButton ID="StopImageButton" runat="server" OnClick="StopImageButton_Click"
                          ImageUrl="~/Stop.jpg" Width="25" Height="25" />
    </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Start" Visible="true">
    <ItemTemplate>
          <asp:ImageButton ID="StartImageButton" runat="server" OnClick="StartImageButton_Click"  
                           ImageUrl="~/Start.jpg" Width="25" Height="25" />
    </ItemTemplate>
</asp:TemplateField>

我也有这段代码,可以在页面加载时隐藏 StopImageButton

I also have this code that hides the StopImageButton when the page loads

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        ImageButton ImgBtn = e.Row.FindControl("StopImageButton") as ImageButton;
        ImgBtn.Visible = false;
    }

}

protected void StopImageButton_Click(object sender, ImageClickEventArgs e)
{

}

protected void StartImageButton_Click(object sender, ImageClickEventArgs e)
{

}

我想做的是,单击 StartImageButton 之后,它将被隐藏,然后现在可以看到 StopImageButton ?救命!

What I want to do is, After Clicking the StartImageButton, It will be hidden, and the StopImageButton will now be then visible? Help!

推荐答案

尝试一下

    protected void StartImageButton_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton StartImageButton = (ImageButton)sender;
        StartImageButton.Visible = false;
        GridViewRow gr = (GridViewRow)StartImageButton.Parent.Parent;
        ImageButton StopImageButton = (ImageButton)gr.FindControl("StopImageButton");
        StopImageButton.Visible = true;
    }

这篇关于图像按钮隐藏和隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆