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

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

  Print Answers RSS
0 OriginalGriff 428
1 Maciej Los 249
2 BillWoodruff 199
3 /\jmot 180
4 Suraj Sahoo | Coding Passion 150
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2014
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