在asp.net中从gridview获取检查的行 [英] Getting Checked rows from gridview in asp.net
问题描述
在ASP.net中有一个 GridView
,其中有一个 CheckBox
列。用户可以切换 CheckBox
。现在,我想要的是当用户点击一个按钮时, GridView
中的所有记录,其中 CheckBox
应检查是否显示。在另一个按钮上,应该显示相反的状态...
我没有得到相同的逻辑。
I have a GridView
in ASP.net where I have a CheckBox
column. The user can toggle the CheckBox
. Now, what I want is that when the user clicks on a button, all the records from the GridView
where the CheckBox
is checked should be displayed. And on another button, the opposite state should be displayed...
I am not getting the logic for the same.
任何人都可以请帮忙我与逻辑..
Can anyone please help me with the logic..
推荐答案
您可以遍历 GridViewRow
并检查 CheckBox
是否使用类似以下内容进行检查
You could iterate through the GridViewRow
s and check if the CheckBox
is checked using something like the following
编辑评论,修正了一些小错误。多谢你们。 (3/20/2013):
Edit from comments, fixed small bugs. Thanks guys. (3/20/2013):
foreach (GridViewRow row in yourGridViewID.Rows)
{
CheckBox check = (CheckBox)row.FindControl("CheckBoxName");
if (check.Checked)
{
//Take Row information from each column (Cell) and display it
}
else
{
//Display in seperate area
}
}
索引将是从0开始的列号,从左到右的列保存 CheckBox
。您需要确保 CheckBox
具有在CheckBoxName处使用的ID名称。如果你没有ID,你也可以使用
The index is going to be the column number starting from 0, going left to right of which column holds the CheckBox
. You need to make sure the CheckBox
has an ID name which is used at CheckBoxName. If you don't have an ID for that, you can also use
CheckBox check = (CheckBox)row.Cells[index].Controls[0];
这篇关于在asp.net中从gridview获取检查的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!