1

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

2
  • What is the column type in your database? is it int or bit? Commented May 27, 2014 at 9:24
  • bit, Am saving it as "true"(1), "false"(0) Commented May 27, 2014 at 9:26

4 Answers 4

2

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;
}
Sign up to request clarification or add additional context in comments.

Comments

1

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.

5 Comments

Thanks Mr. Sekar, My probl;em is how to get the value and bind it in Checkbok and it should be checked If the value is saved as True in Database
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# !Convert.ToBoolean(Eval("Mycolumnname")) %>' /> In userprofile.aspx.cs file...How should i bind sir?!
<%# Convert.ToBoolean(Eval("Mycolumnname").ToString()) %>
am using this in .cs SqlConnection con = new SqlConnection (@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\PRJT2\Documents\Visual Studio 2012\Projects\divlesson\divlesson\App_Data\divlession.mdf;Integrated Security=True"); con.Open(); SqlDataAdapter Comm = new SqlDataAdapter("SELECT HobbyID,IsChecked from Hobbies where HobbyID='1'", con); Boolean result; result = Convert.ToBoolean(CheckBox1.Checked); con.Close(); I couldn't get my Check box Checked Even the value is 'True' in the Database
Sir , Any soultio0n how should in get checkbox binded from database?
0
<asp:checkbox id="Cluster" runat="server" checked='<%# Eval("Cluster") == DBNull.Value ? false : Eval("Cluster") %>' />

4 Comments

Kindly Tell me the code which i holud use in .cs page?
above code is of design...cluster is the column name
Say two columns in Database UserID(int) and Ischecked(bit)
Mr pranav I understood that sir, I need help how to call the checkbox in pageload in cs page from my database
0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.