I have a listbox that I populate it from the database; then on submit check for selected items. It always returns false (not selected). However if I hardcode the values into the listbox I do find the correct selected values.
Any idea why this would be?
Thanks for your thoughts!
Any idea why this would be?
Code:
private void Page_Load(object sender, System.EventArgs e){
dba = new DBA.DBAccessor();
dba.ConnStr = @"Data Source=someDS;User ID=someID;Password=somePWD;";
sql = "SELECT GID, DESC FROM SOME_GROUPS";
ds = dba.GetOraDataSet(sql,"Groups");
lstRoles.DataSource=ds.Tables["Groups"];
lstRoles.DataTextField="DESC";
lstRoles.DataValueField="GID";
lstRoles.DataBind();
}
private void Button1_Click(object sender, System.EventArgs e){
ArrayList al = GetSelectedItems(lstRoles);
// do something with the array "al"
}
private ArrayList GetSelectedItems(ListBox listBox){
ArrayList returnVal = new ArrayList();
foreach(ListItem item in listBox.Items)
if(item.Selected) returnVal.Add(item.Value);
return returnVal;
}
Thanks for your thoughts!