Click here to Skip to main content
15,031,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have multiple selected value from checklistbox but my code return only last selected value ...

SQL
i hv 2 tables.
1 student table and 1 subject table. i want subject value from sub table.
but my problm is that when i select it from grid view it fills only last selected value....from sub table.....and not all values...
i have done all the things dynamically....


code is:
C#
String qr = "select * from stusub where StuID='" + gv1.SelectedRow.Cells[1].Text + "' ";
SqlCommand cm = new SqlCommand(qr, conn);
conn.Open();
SqlDataReader dr1 = cm.ExecuteReader();

DataTable dt1 = new DataTable();
dt1.Load(dr1);
for (int i = 0; i < dt1.Rows.Count; i++)
{
  lbSubject.SelectedValue = Convert.ToString(dt1.Rows[i]["SubID"]);
}
conn.Close();
Posted
Updated 6-Sep-12 21:30pm
v3

Can you explain , what exactly u mean , do u have check box n each row of gridview or multiple check box on a single row

if you one check box on every row of Gridview and then make it as template column

Then using Grdivew Rowcommand , you can do the for each loop.
   
Comments
_Amy 7-Sep-12 3:22am
   
You should not ask your doubts here in the solution box.
Member 9332883 7-Sep-12 3:23am
   
see.
i hv 2 tables.
1 student table and 1 subject table. i want subject value from sub table.
but my problm is that when i select it from grid view it fills only last selected value....from sub table.....and not all values...
i have done all the things dynamically....i need it urgently...plz make it fast....
Hi,
You should follow these steps:
Quote:
1. Fetch all the selected row from your gridview.
2. Store it in a string separated with comma. Like (2, 3, 4, 5)
3. Now use IN operator in your sql query. Like:
"SELECT * FROM stusub WHERE StuID IN '" + GridviewSelectedRows + "' ";
Here GridviewSelectedRows is the the string which you are framing with comma separation.
4. Now get the recordset from database.


Follow the steps and try your best.
All the best.
--Amit
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900