I hope my question is describing itself =) I tried to do everything but I don’t seem to get why it’s not working!
My CheckBoxList :
<asp:CheckBoxList ID="chkbxlstCuisines" runat="server">
</asp:CheckBoxList>
My code-behind :
protected void Page_Load(object sender, EventArgs e)
{
string cuisinesSelectStatement = "SELECT Cuisines.CuisineId, Cuisines.CuisineType FROM Cuisines";
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDbConnection"].ConnectionString);
SqlCommand comm = new SqlCommand(cuisinesSelectStatement , conn);
SqlDataReader reader1;
conn.Open();
reader1 = comm.ExecuteReader();
chkbxlstCuisines.DataSource = reader1;
chkbxlstCuisines.DataBind();
while (reader1.Read())
{
chkbxlstCuisines.DataValueField = reader1["CuisineId"].ToString();
chkbxlstCuisines.DataTextField = reader1["CuisineType"].ToString();
}
//conn.Close();
}
I hope someone figure it out, I know it’s gonna be a little mistake because I fixed this error before but now I really don’t know what’s wrong!
Thanks in advance guys! =)
Edit:
I think the problem is with the casting, because the output is five checkboxes and my database contains exactly five items!
OUTPUT :
System.Data.Common.DataRecordInternal
System.Data.Common.DataRecordInternal
System.Data.Common.DataRecordInternal
System.Data.Common.DataRecordInternal
You don’t need the “while” code; your code should be:
DataValueField is the name of the field in your bound object that contains value.
DataTextField is teh name of teh field in your bound object that contains display text.