在运行时在gridview上绑定多个图像 [英] Binding multiple images at run time on gridview

查看:111
本文介绍了在运行时在gridview上绑定多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在一个项目模板中有3个不同的图像.根据某些条件,我想使这些可见或不可见.样本片段就像

如果(条件A ==真)
然后Img1.visible = true
否则if(条件B == true)
然后Img1和Img2.Visible = True
其他Img1,Img2和Img3.visible = true.

我的代码应该是什么?在哪里?请提供任何帮助或任何提示?

Hi,

I have 3 different images inside one Item Template. Depending upon certain condition, I want to make those visible or invisible. The sample snippet is like

If(condition A== True)
then Img1.visible=true
else if(condition B ==true)
then Img1 and Img2.Visible=True
Else Img1,Img2 and Img3.visible=true.

what should be my code? and where? Any Help or any hint please??

推荐答案

使用gridview的RowDataBound事件.根据条件设置图像的可见性.

Use gridview''s RowDataBound event. Based on the condition set the visibility of the images.

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
      Image img1 = (Image)e.Row.FindControl("img1");
      Image img2 = (Image)e.Row.FindControl("img2");
      Image img3 = (Image)e.Row.FindControl("img3");
      // Now check your conditions here..

    }
  }


这篇关于在运行时在gridview上绑定多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆