0

我的网格视图中有一个名为 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然后现在将可见?帮助!

4

2 回答 2

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;
    }
于 2013-07-15T05:43:03.820 回答
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;
}
于 2013-07-15T03:56:02.953 回答