Reputation: 117
Am working on a registration page, Where here user has checkbox to select the location and services, Am saving the data in Database as 1 if checked , 0 if form is saved unchecked.
Now in the Edit page for the user Like profile page, am binding the data which is present in database.
I don't know how to bind the checkbox to bind if the user already checked and in database it is saved as '1"
Am using C# and Asp.net. Kindly Help
Upvotes: 1
Views: 11369
Reputation: 19
You can use the below code to get the value from the database and represent it in the web form:
CheckBox1.Checked = rdr.GetBoolean(3);
Upvotes: 0
Reputation: 965
You will get either 0 or 1 from database right?? SO, store it in integer variable a;
{
if (a==0)
chkbox1.checked = false
else
chkbox1.checked = true;
}
Upvotes: 2
Reputation: 965
<asp:checkbox id="Cluster" runat="server" checked='<%# Eval("Cluster") == DBNull.Value ? false : Eval("Cluster") %>' />
Upvotes: 0
Reputation: 17604
You can convert you int value 1
or 0
and then assign to your check-box checked property.
If they are string type then convert them to int
and then to Boolean
CheckBox1.Checked = Convert.ToBoolean(0); // False - Not checked.
CheckBox1.Checked = Convert.ToBoolean(1); // True - checked.
You can use this method Convert.ToBoolean(value)
to convert string to boolean
CheckBox1.Checked = Convert.ToBoolean("false"); // False - Not checked.
CheckBox1.Checked = Convert.ToBoolean("true"); // True - checked.
Upvotes: 1