I have checkboxlist in aspx page.It fills from database while run application.I use Edit link button.Now i use MySQL reader to read data from database.
txtPFirstName.Text = dr[3].ToString();
txtPMiddleName.Text = dr[4].ToString();
txtPLastName.Text = dr[5].ToString();
CheckBoxList2.SelectedValue = dr[29].ToString();
For textbox it reads the data correctly.But in checkboxlist the data is not retrieved from database.How I retrieve data from database in to Dropdownlist?Can anyone help me to do this?
Sanjeeb LenkaPosted Jul 22, 2013, 6:51 AM
string[] Branches = dr[29].ToString().Split(',');
foreach (ListItem li in CheckBoxList2.Items)
{
if (Branches.Contains(li.Value))
li.Selected = true;
}
Sanjeeb LenkaPosted Jul 22, 2013, 7:24 AM
Kavi sujaPosted Jul 22, 2013, 7:20 AM
Iftikar,Sanjeeb thank you for your replies.It's works for me.
Iftikar HussainPosted Jul 22, 2013, 6:52 AM
Regards,
Iftikar
Kavi sujaPosted Jul 22, 2013, 6:44 AM
I'm getting check box list value as comma separated string.
Sanjeeb LenkaPosted Jul 22, 2013, 5:40 AM
Iftikar HussainPosted Jul 22, 2013, 5:34 AM
Regards,
Iftikar
Kavi sujaPosted Jul 22, 2013, 5:29 AM
if ((string)checkedListBox1.Items[i] == value) here 'string' and 'value' represents what?
Iftikar HussainPosted Jul 22, 2013, 5:19 AM
Regards,
Iftikar
Kavi sujaPosted Jul 22, 2013, 5:10 AM
I attach the code here.
Iftikar HussainPosted Jul 22, 2013, 4:54 AM
You need to first bind the data to your checkbox list. Can you share your aspx code?
Regards,
Iftikar