如何使使用的DataBinder.Eval一个GridView选中复选框 [英] How to make a checkbox checked in a gridview using DataBinder.Eval

查看:206
本文介绍了如何使使用的DataBinder.Eval一个GridView选中复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让检查一个复选框,如果值是1或0基本上在我的数据库,我有
一个名为场活动(位,不为空),我可以传递值到GridView ..但现在我要把它检查是否该位是1还是不如果检查该位为0,但它不工作..它只是显示选中,但位为1。

I am trying to make a checkbox checked if the value is 1 or 0 basically in my database i have a field called Active (bit, not null) and i can pass the value to the gridview.. but now i am trying to make it checked if the bit is 1 or not checked if the bit is 0 but its not working.. it just shows unchecked but the bit is 1.

   <ItemTemplate>
   <asp:CheckBox ID="ItemCheck" runat="server"
    Enabled='<%# (DataBinder.Eval(Container.DataItem, "Active")) %>' />
   </ItemTemplate>

任何帮助将是非常美联社preciated

Any help would be much appreciated

推荐答案

给这一个镜头:

<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%#Convert.ToBoolean(Eval("Active"))%>' .. />

您也许可以这样来做太:

You can probably do it this way too:

<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%#((bool)Eval("Active"))%>' .. />

这篇关于如何使使用的DataBinder.Eval一个GridView选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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