图像按钮隐藏和取消隐藏

时间:2013-07-15 03:41:56

标签: c# asp.net

我的gridview中有一个名为StopImageButton和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

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现在可见了吗?救命啊!

2 个答案:

答案 0 :(得分:0)

protected void StartImageButton_Click(object sender, GridViewRowEventArgs e)
{
    //hide StartImageButton
    ImageButton StartBtn = e.Row.FindControl("StartImageButton") as ImageButton;
    StartBtn.Visible = false;

    //UnHide StopImageButton
    ImageButton StopBtn = e.Row.FindControl("StopImageButton") as ImageButton;
    StopBtn.Visible = true;
}

答案 1 :(得分:0)

试试这个

    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;
    }