Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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
Posted 8-Mar-12 21:12pm
Edited 8-Mar-12 21:32pm
v2
Comments
ProEnggSoft at 9-Mar-12 2:32am
   
Edit - Pre tag for ASP.NET code added - PES
Nilesh Patil Kolhapur at 9-Mar-12 2:37am
   
Your Code is ok check returned value
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

<ItemTemplate>
    <asp:CheckBox ID="chkReimbursable" runat="server"
       Checked='<%# GetStatus(Eval("Reimbursable")) %>'/>
</ItemTemplate>
 

protected bool GetStatus(string str)
   {
       if (str == "1")
           return true;
       else
           return false;
   }
  Permalink  
Comments
Vani Kulkarni at 26-Jun-12 2:54am
   
My 5!
manoj kumar choubey at 26-Jun-12 3:01am
   
My vote is +5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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

       }
         
}
 
 

hope you understand and this will help you...
in Item Template :
 
<asp:TemplateField HeaderText="Select Document">
 <ItemTemplate>
                <asp:checkbox id="CheckBox1" runat="server" />          
 </ItemTemplate>                                              
 
 
 

  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 434
1 Maciej Los 420
2 OriginalGriff 340
3 CHill60 240
4 Abhinav S 220
0 Sergey Alexandrovich Kryukov 10,102
1 OriginalGriff 9,495
2 Peter Leow 5,241
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,076


Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 30 Jan 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100