在Arraylist中存储gridview的行索引 [英] store row index of gridview in Arraylist
本文介绍了在Arraylist中存储gridview的行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在gridview中选择一行时,我想将选定的行索引存储在arraylist中,最后更新数据库中包含所有行索引的数据库。
怎么能我实现了这个目标吗?
解决方案
试试这个:
List< int> L = new List< int>();
datagridview点击事件:
private void dataGridView1_MouseClick( object sender,MouseEventArgs e)
{
int k = Convert.ToInt32(dataGridView1.CurrentRow.Index) ;
if (!L.Contains(k))
{
L.Add(k);
}
}
希望它能帮到你...
< blockquote>你可以在网格视图中的模板化字段中使用Button / ImageButton或任何你想要的控件。
假设您按照以下使用Image按钮,或者您可以根据您使用的控件更改代码
受保护 void ImageButton1_Click( object sender,ImageClickEventArgs e)
{
ImageButton btn =(ImageButton)sender;
GridViewRow gvr =(GridViewRow)btn.NamingContainer;
int index = gvr.ItemIndex; // 行索引
}
When I select a row in the gridview , I want to store the selected row index in arraylist and at the end update the database with all row indexes whih are present in the arrayist.
How can i achieve this?
解决方案
try this :
List<int> L = new List<int>();
on datagridview click event :
private void dataGridView1_MouseClick(object sender, MouseEventArgs e) { int k = Convert.ToInt32(dataGridView1.CurrentRow.Index); if (!L.Contains(k)) { L.Add(k); } }
Hope it will help you ...
You can use Button/ImageButton or any control you want in templated field in grid view.
Suppose you are using Image button as per following , or you can change the code according to control you are using
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { ImageButton btn = (ImageButton)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; int index = gvr.ItemIndex;//Index of row }
这篇关于在Arraylist中存储gridview的行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文