我如何知道在gridview asp.net中哪些复选框已被选中/已标记 [英] how do I we get to know which all the check box's are TICKED/MARKED in gridview asp.net

查看:110
本文介绍了我如何知道在gridview asp.net中哪些复选框已被选中/已标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net页面中有Datagrid,其中包含以下提到的数据
设备名称|第1列|列2
---------------------------------------
iPad |复选框|复选框
iPhone |复选框|复选框

这里Device_Name,Column1和Column2是列名,在这些列下,我们在这两个列上都有复选框,请问有没有机构可以帮助我我如何知道所有选中的复选框都已打勾/标记.

我们应该可以随时在任何复选框上打勾

你能帮我一个吗


感谢Nirav和Raje的快速响应,但是您的代码无法正常工作.

这是自动生成Gridview的代码
====================================== <= >

I have Datagrid in asp.net page with the below mentioned data
Device_Name | Column1 | Column2
---------------------------------------
iPad | CHECK BOX | CHECK BOX
iPhone | CHECK BOX | CHECK BOX

here Device_Name,Column1 and Column2 are column names, under these columns we have check boxes on both the columns, Please can any body help me how do I we get to know which all the check box''s are TICKED/MARKED.

We should be able to tick any check box at any time

Could you please some one help me one this


Thanks Nirav and Raje for your quick response, However your code is not working.

Here is my Code to auto generate my Gridview
===============================================

protected void GrdOSInfo_RowDataBound(object sender, GridViewRowEventArgs e)
       {
        if (e.Row.RowType == DataControlRowType.DataRow)
           {
               for (int i = 1; i < 3; i++)
               {
                   //foreach (GridView row in GridView1.Rows)
                   //{
                   CheckBox chk = new CheckBox();
                   chk.EnableViewState = true;
                   chk.Enabled = true;
                   chk.ID = "chkb"+i;

                   e.Row.Cells[i].Controls.Add(chk);
                   //}
               }
           }
       }


==============================================

因此,在这里,我基本上想知道如何从Grid视图中为数组列表分配检查值(只是为了识别被勾选的数组)(出于存储目的,稍后我将把此数组列表传递给下一页).

谁能帮助我,我将非常感谢您的帮助.


================================================

So here basically I want to know how do I assign checked value (just to identify which are been ticked) to array list from Grid view (for storing purpose, later I will pass this arraylist to next page).

Can any one please help me on this, I will be really great full to your help

推荐答案

使用ASP.Net:
Using ASP.Net :
int EmpId = 0;
foreach(Gridviewrow gvr in Gridview1.Rows)
{
 if(((CheckBox)gvr.findcontrol("chkId")).Checked == true)
 {
    EmpId = Convert.ToInt32(gvr.cells["EmployeeId"]);
 }
}



祝你好运



Good luck


尝试一下.. :)

try this.. :)

foreach(GridViewRow gvrow in gvGrid.Rows)
{
CheckBox chk1 = (CheckBox)gvrow.FindControl("chkSelect1"); //Find control of checkbox1
CheckBox chk2 = (CheckBox)gvrow.FindControl("chkSelect2"); //Find control of checkbox22
if (chk1 != null & chk1.Checked)
{
  //do stuff when checked
}
else
{
//do stuff when UnChecked
}

if (chk2 != null & chk2.Checked)
{
  //do stuff when checked
}
else
{
//do stuff when UnChecked
}
}


感谢Nirav和Raje的快速响应,但是您的代码无法正常工作.

这是自动生成Gridview的代码
====================================== <= >
Thanks Nirav and Raje for your quick response, However your code is not working.

Here is my Code to auto generate my Gridview
===============================================
protected void GrdOSInfo_RowDataBound(object sender, GridViewRowEventArgs e)
       {
        if (e.Row.RowType == DataControlRowType.DataRow)
           {
               for (int i = 1; i < 3; i++)
               {
                   //foreach (GridView row in GridView1.Rows)
                   //{
                   CheckBox chk = new CheckBox();
                   chk.EnableViewState = true;
                   chk.Enabled = true;
                   chk.ID = "chkb"+i;

                   e.Row.Cells[i].Controls.Add(chk);
                   //}
               }
           }
       }


==============================================


================================================

So here basically I want to know how do I assign checked value (just to identify which are been ticked) to array list from Grid view (for storing purpose, later I will pass this arraylist to next page).



有人可以帮我吗,我将非常感谢您的帮助



Can any one please help me on this, I will be really great full to your help


这篇关于我如何知道在gridview asp.net中哪些复选框已被选中/已标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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