I have a checkbox list in my page and try to databind it. Here is what i do:
SqlCommand cmd=new SqlCommand("Select subj,numb,section from Courses where term=@term",CommonFunctions.con);
cmd.Parameters.AddWithValue("@term",CommonFunctions.currentTerm);
SqlDataAdapter da=new SqlDataAdapter(cmd);
da.Fill(dt);
checkboxlist_courses.DataSource = dt;
checkboxlist_courses.DataTextField = "subj";
checkboxlist_courses.DataBind();
This works fine. The problem is, i can only show the column "subj" in the checkbox list. What i want to do is, i want to show "subj" + "numb" + "section" in the checkbox list. So, what can i do about this?
I tried
checkboxlist_courses.DataTextField = "subj" + "numb" + "section";
but it did not work.
I also tried
SqlCommand cmd=new SqlCommand("Select subj,numb,section as fullname from Courses where term=@term",CommonFunctions.con);
checkboxlist_courses.DataTextField = "fullname";
But this time only "section" column is displayed. Thanks
sujnumsection? Because all you are doing is combining the string, then assigning it to the property.