从Gridview中的某些行隐藏图像按钮

xor*_*wer 1 .net c# asp.net gridview visual-studio

我在gridview的模板字段中添加了一个图像按钮.gridview包含20行.在所有行中,都添加了图像按钮.现在,如果我想从某些行隐藏图像按钮,我该怎么办?

我无法从gridview中删除那些会远离所有行的内容.

请指导

如有任何疑问,请告诉我.

谢谢!

Pra*_*ana 6

RowDataBound在GridView中使用Event avaialbe,您可以在其中隐藏给定行所需的控件.

void grv_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
      if(condition)
      {
       ImageButton imgBtn= (ImageButton)e.Row.FindControl("mybuttonid");
       imgBtn.Visible = false;
      }
  }
}
Run Code Online (Sandbox Code Playgroud)