使用带以下列的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
}
}但它并没有隐藏这一形象。如何以编程方式对某些行使用obout网格隐藏图像?手前谢谢。
发布于 2019-11-13 17:21:35
如果找到了答案,以防将来有人遇到这种情况:
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 = "";
}
}
}https://stackoverflow.com/questions/58825436
复制相似问题