在 asp.net 中从 gridview 获取选中的行 [英] Getting Checked rows from gridview in asp.net

查看:16
本文介绍了在 asp.net 中从 gridview 获取选中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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 GridViewRows 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屋!

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