Obout Grid:仅在某些行上隐藏图像在网格上

时间:2019-11-12 19:28:46

标签: asp.net obout

在下面的列中使用obout网格:

<obg:Column ID="Image" DataField="" HeaderText="" Width="50" runat="server">
   <TemplateSettings TemplateId="ImageTemplate" />
</obg:Column>

以及以下模板:

<Templates>
  <obg:GridTemplate runat="server" ID="ImageTemplate">
    <Template>
      <img src="images/test.png" title="test" />
    </Template>
  </obg:GridTemplate>
</Templates>

我试图以编程方式在某些行上隐藏图像:

protected void grd_RowDataBound(object sender, GridRowEventArgs e)
{
    if (testpassed())
    {
        e.Row.Cells[1].Text = "";  // Column 2 is the image
    }
}

但是它没有隐藏图像。如何仅对某些行使用圆角网格以编程方式隐藏图像?先谢谢你。

1 个答案:

答案 0 :(得分:0)

如果找到答案,以防将来有人碰到这个问题:

protected void grd_RowDataBound(object sender, GridRowEventArgs e)
{
  // Check if this is a DataRow
  if (e.Row.RowType == GridRowType.DataRow)
  {
    // Check if we are hiding the image
    if (testpassed())
    {            
      // Retrieve Image Cell (Column 2 in my case)
      GridDataControlFieldCell cell = e.Row.Cells[1] as GridDataControlFieldCell;

      // Retrieve Literal Control with Image Source Html (Found at Level 5)
      LiteralControl imgTag = cell.Controls[0].Controls[0].Controls[0].Controls[0].Controls[0] as LiteralControl;

      // Remove Html <img src.. code from Literal Control in order to hide image
      imgTag.Text = "";
    }
  }
}