检索gridview上的多个选定项选定索引已更改事件 [英] retrive multiple selected items on gridview selected index changed event

查看:62
本文介绍了检索gridview上的多个选定项选定索引已更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从复选框中选择了多个值,但是我的代码仅返回最后一个选择的值...

i have multiple selected value from checklistbox but my code return only last selected value ...

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:

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();

推荐答案

您能解释一下,您的意思是什么,在gridview的每行中是否都有复选框或多个复选框?单行

如果在Gridview的每一行上选中一个复选框,然后将其作为模板列

然后,使用Grdivew Rowcommand,可以为每个循环执行.
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.



您应该按照以下步骤操作:
Hi,
You should follow these steps:
报价:

1.从gridview获取所有选定的行.
2.将其存储在用逗号分隔的字符串中.像(2,3,4,5)
3.现在在您的SQL查询中使用IN运算符.喜欢:
"SELECT * FROM stusub WHERE StuID IN ''" + GridviewSelectedRows + "'' ";
GridviewSelectedRows 是您要用逗号分隔的字符串.
4.现在从数据库获取记录集.

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.



请按照步骤操作,并尽力而为.
祝一切顺利.
--Amit



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


这篇关于检索gridview上的多个选定项选定索引已更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆