根据数据库值显示或取消选中gridview的复选框... [英] Display Checkboxes of gridview checked or unchecked according to Database value...

查看:77
本文介绍了根据数据库值显示或取消选中gridview的复选框...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据数据库值显示或取消选中gridview的复选框...

i数据库paymentid(int)中有3个字段,methodname(varchar50),Reimbursable(bit)





我有gridview,其中id(标签),methodname(标签),Reimbursable(复选框)



i绑定数据与gridview bt复选框值未选中。不能找到错误..





Display Checkboxes of gridview checked or unchecked according to Database value...
i have 3 field in database paymentid(int),methodname(varchar50),Reimbursable(bit)


and i have gridview where id(label),methodname(label),Reimbursable(checkbox)

i bind data with gridview bt checkbox value is unchecked.unable to find error..


<ItemTemplate>
    <asp:CheckBox ID="chkReimbursable" runat="server" 

       Checked='<%# Convert.ToBoolean(Eval("Reimbursable")) %>'/>
</ItemTemplate>





Thanx



Thanx

推荐答案

<ItemTemplate>
    <asp:CheckBox ID="chkReimbursable" runat="server"

       Checked='<%# GetStatus(Eval("Reimbursable")) %>'/>
</ItemTemplate>

< br $> b $ b






protected bool GetStatus(string str)
   {
       if (str == "1")
           return true;
       else
           return false;
   }


试试这个:

Try This :
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
       {

           int x = System.Convert.ToInt32(e.Row.RowIndex);
           CheckBox chk = (CheckBox)e.Row.FindControl("CheckBox1");
           // your select query from your database table
           // if it finds record from that table make chk.checked=true else false

       }
         
}







希望你明白,这对你有帮助...
$ b项目模板中的$ b:






hope you understand and this will help you...
in Item Template :

<asp:TemplateField HeaderText="Select Document">
 <ItemTemplate>
                <asp:checkbox id="CheckBox1" runat="server" />          
 </ItemTemplate>                                              


< itemtemplate> ;

< asp:checkbox id =chkReimbursablerunat =serverenable =truexmlns:asp =#unknown>

Checked =' <%#GetStatus(Eval(Reimbursable))%>'/>
<itemtemplate>
<asp:checkbox id="chkReimbursable" runat="server" enable="true" xmlns:asp="#unknown">
Checked='<%# GetStatus(Eval("Reimbursable")) %>'/>


这篇关于根据数据库值显示或取消选中gridview的复选框...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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