'read data in database to checkboxlist, how can i read it?
How can I read the data in the database so when it reads. it will check the specific data?
Here is my full code:
string query = "SELECT TypeName from TypeTransaction WHERE UANumber = '" + id + "'";
connUser.Open();
cmd.CommandText = query;
sdr = cmd.ExecuteReader();
while(sdr.Read())
{
ListItem item = new ListItem();
item.Text = sdr.GetString(0);
lbTypes.Items.Add(item);
}
List<string> iteme = new List<string>();
for(int j = 0; j < lbTypes.Items.Count; j++)
{
for(int i = 0;i < chkTypes.Items.Count;i++)
{
if(lbTypes.Items[j].Text == chkTypes.Items[i].Text)
{
chkTypes.Items[i].Selected = true;
}
else
{
chkTypes.Items[i].Selected = false;
}
}
}
my listbox has a value of GDS and Email in a seperate line, but when i run it, the Email Checkbox is the one only selected. it should be both Email and GDS that is selected in the checkboxlist.
Solution 1:[1]
Take a look on below url which helps you http://www.aspsnippets.com/Articles/Bind-CheckBoxList-from-Database-in-ASPNet.aspx
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Glorfindel |
