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 LenkaRank #301 · 8.3K reputationPosted Jul 22, 2013, 2:51 AM EDT
string[] Branches = dr[29].ToString().Split(',');
foreach (ListItem li in CheckBoxList2.Items)
{
if (Branches.Contains(li.Value))
li.Selected = true;
}
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 22, 2013, 12:54 AM EDT
You need to first bind the data to your checkbox list. Can you share your aspx code?
Regards,
Iftikar
Kavi sujaRank #6,237 · 272 reputationPosted Jul 22, 2013, 1:10 AM EDT
I attach the code here.
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 22, 2013, 1:19 AM EDT
Regards,
Iftikar
Kavi sujaRank #6,237 · 272 reputationPosted Jul 22, 2013, 1:29 AM EDT
if ((string)checkedListBox1.Items[i] == value) here 'string' and 'value' represents what?
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 22, 2013, 1:34 AM EDT
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 22, 2013, 1:40 AM EDT
Kavi sujaRank #6,237 · 272 reputationPosted Jul 22, 2013, 2:44 AM EDT
I'm getting check box list value as comma separated string.
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 22, 2013, 2:52 AM EDT
Regards,
Iftikar
Kavi sujaRank #6,237 · 272 reputationPosted Jul 22, 2013, 3:20 AM EDT
Iftikar,Sanjeeb thank you for your replies.It's works for me.
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 22, 2013, 3:24 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts