I am trying to retrieve multiple values from the session variable in which I stored the values as List. Here’s the code I applied but this gives me only the lst value from the list in the output. I would really appreciate some help!
Array k= yourlist.ToArray();
for (Int32 i = 0; i < k.Length; i++)
{
Int32 x = Convert.ToInt32(k.GetValue(i));
SqlCommand cmd2 = new SqlCommand("select id,name from plugins where id =" + x, con);
SqlDataReader dr2 = cmd2.ExecuteReader();
if (dr2.HasRows)
{
while (dr.Read())
{
ListBox2.DataSource = dr2;
ListBox2.DataBind();
}
}
dr2.Close();
cmd2.Dispose();
}
Thanks!
First of all you execute multiple queries, each returning one line, and you re-bind this in your loop. You should get all the rows in one query, and then bind the results to your control.
You might have more luck with something like this: