Can I bind multiple rows to a checkbox list?

I know this is doable using a repeater, not sure if it's doable using a checkboxlist.

I have a list of offices, i want to display them (name and officeid will be checkbox list id) and have the user check the relevant ones.
Do i have to use a repeater?
LVL 8
CamilliaAsked:
Who is Participating?
 
ddayx10Connect With a Mentor Commented:
If I understand your question clearly yes <see snippet>.

Pretty much psuedo-code but it should be really close. If you know how to do it with a repeater this should be pretty similar.

Here's an article:
http://www.4guysfromrolla.com/webtech/072701-1.shtml

If you want different approach its pretty much out there with google (radiobuttonlist databind sqldatasource for example).
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("someconnstr");
        System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT OfficeID, Name FROM SomeTable",conn);
        conn.Open();
        System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
        rbl.DataSource = dr;
        rbl.DataTextField = dr["Name"].ToString();
        rbl.DataValueField = dr["OfficeId"].ToString();
        rbl.DataBind();

Open in new window

0
 
ddayx10Commented:
stupid psuedo-code will get you every time...messed that up try again.
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("someconnstr");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT OfficeID, Name FROM SomeTable",conn);
conn.Open();
System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
rbl.DataSource = dr;
rbl.DataTextField = "Name";
rbl.DataValueField = "OfficeId";
rbl.DataBind();

Open in new window

0
 
ddayx10Commented:
Ah jeez I'm going to bed. Too sleepy to pay any attention properly. Anyway same deal with checkboxlist as radiobuttonlist.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.