Why are my .NET CheckListBox Items not selected?

kaups93

New Member
I have a web application I am programming that builds a SQL query based on user input. I am currently using a few check boxes without problems. However, instead of hard-coding the check boxes, I dynamically populated them on \[code\]Page_Load\[/code\] with the following code:\[code\]protected void Page_Load(object sender, EventArgs e){ //init(); sql.Open(); if (!Page.IsPostBack) { SqlCommand cmd = new SqlCommand("SELECT DISTINCT [value] FROM
", sql); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) chkLst.Items.Add(rdr[0].ToString()); rdr.Close(); } sql.Close();}\[/code\]Populating works perfectly. However, when I try to retrieve \[code\]chkLst.Items.Selected\[/code\] property, it's always set to false, and thus renders the list useless for filtering. Below is the relevant segment of my code that executes on submit:\[code\]foreach (ListItem li in chkLst.Items) if (li.Selected) cmd += li.Text;\[/code\]Since the Selected property is always false, my command always comes up empty. What can I do to fix this?
 
Back
Top