Click here to Skip to main content
11,707,167 members (49,936 online)
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 20:12pm
Edited 8-Mar-12 20: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 145
1 OriginalGriff 141
2 chainerlt 110
3 Maciej Los 80
4 ppolymorphe 79
0 OriginalGriff 9,178
1 Sergey Alexandrovich Kryukov 8,512
2 CPallini 5,189
3 Maciej Los 4,766
4 Mika Wendelius 3,696


Advertise | Privacy | Mobile
Web01 | 2.8.150819.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