Gridview中的项目模板 [英] Item Template in Gridview

查看:77
本文介绍了Gridview中的项目模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

比较Item模板中的值,应将其与字符串进行比较.

Hello all,

Comparing the value from Item template,it should be compare with the string.

  <itemtemplate>
  <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="false" 

             CommandArgument="<% #  Container.DataItemIndex %>" CommandName="EVA" 

             ImageUrl="~/Images/cross.gif" 

             Visible='<%# Eval("EvaluationComplete") = 'NO' %>' />
 
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="false" 

             CommandArgument="<% #  Container.DataItemIndex %>" CommandName="EVA" 

             ImageUrl="~/Images/tick.gif" 

             Visible='<%# Eval("EvaluationComplete") = 'YES' %>' />
  </itemtemplate>

推荐答案

解决问题的更好方法是将图像名称重命名为YES.gif而不是tick.gif和NO.gif而不是cross.gif

和写为

better way to do your problem is rename your image name as YES.gif instead of tick.gif and NO.gif instead of cross.gif

and the write coding as

<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="false" 

             CommandArgument="<% #  Container.DataItemIndex %>" CommandName="EVA" 

             ImageUrl='<%"~/Images/"+ Eval("EvaluationComplete")+".gif" %>'

            />



//逻辑

它将根据数据库中的值调用相应的图像.不需要设置可见的true和false



//logic

it will call the corresponding images based on the values in database. no need to set visible true and false


您可以在使用Eval或Bind Expression时使用Binding Expression进行条件绑定.请尝试以下方式.
这将为您工作!
You can do Conditional Binding with Binding Expression while using Eval or Bind Expression. Try the following way.
This will work for you !
<asp:TemplateField>
             <ItemTemplate>
                 <asp:Image ImageUrl='<%# "/Images/" + (Convert.ToBoolean(Eval("EvaluationComplete")) ? "tick" : "cross") + ".png" %>' runat="server" />
             </ItemTemplate>
         </asp:TemplateField>



EvaluationComplete可以为True或False,并且基于绑定期间的图像将更改.您也可以在代码隐藏"中执行相同的操作.但这将是处理的好方法.
您也可以在此处输出 [



EvaluationComplete could either True or False and based on the during binding image will change. You can do the same thing in Code Behind as well. But this is going to be good way to handle.
You can check out the output here as well Output[^]

Hope this helps !


这篇关于Gridview中的项目模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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