在gridview中单击时的复选框 [英] checkboxes when clicked in gridview

查看:62
本文介绍了在gridview中单击时的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个GridView控件,该控件显示Branch1项的所有信息.

我在Gridview的第一列中有所有复选框,并在Gridview之外有一个按钮.
当我单击某些复选框并单击按钮时,

选定的复选框行应显示在另一页Gridview中(将项目从一个分支转移到另一个分支).

有人可以帮助我或为我提供示例代码.

Hi
I have a GridView control which displays all the information of Branch1 Items.

and i have all checkboxes in first colum of Gridview,and a button outside Gridview.
when i click on some of the checkboxes and click on the button

The selected checkboxes rows should be displayed in another page Gridview(transfer the items from one branch to another branch).

can someone help me or provide me with sample code.

推荐答案

您好,
试试这个:
在第一页中:
Hi,
Try this:
In 1st page:
DataTable dt =new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Name");
foreach (GridViewRow grRow in GridView1.Rows)
{
    CheckBox chk = (CheckBox)grRow.FindControl("checkboxId");
    //checking for the checkbox, if checked!
    if (chk.Checked)
    {
        Label ID = (Label)grRow.FindControl("LabelForID");
        Label Name = (Label)grRow.FindControl("LabelForName");
        //Adding the selected row in table
        dt.Rows.Add(ID.Text, Name.Text);
    }
}
//Storing the data-table in session
Session["SelRows"] = dt;



在第二页:



In 2nd page:

DataTable dt =new DataTable();
//Getting the data form sessoin
dt = Session["SelRows"] as DataTable;
if(dt != null)
{
    grid2.DataSource = dt;
    grid2.DataBind();
}





祝一切顺利.
--Amit





All the best.
--Amit


在单击按钮时添加此代码.我只用了两个字段(Id& Name)进行了两个gridview.

Add this code in your button click. I have taken two gridview with just two field (Id & Name).

DataTable dt =new DataTable();
            dt.Clear();
            dt.Columns.Add("Id");
            dt.Columns.Add("Name");


            for (int i = 0; i < grid.Rows.Count; i++)
            {
                GridViewRow grRow = grid.Rows[i];
             if (grRow.RowType == DataControlRowType.DataRow)
               { 
                CheckBox chk = (CheckBox)grRow.Cells[0].FindControl("checkboxId");
                if (chk.Checked)
                {
                    Label ID = (Label)grRow.Cells[i].FindControl("LabelForID");
                    Label Name = (Label)grRow.Cells[i].FindControl("LabelForName");
                    dt.Rows.Add(ID.Text, Name.Text);
                }
              }
            }
            if (dt.Rows.Count > 0)
            {
                grid2.DataSource = dt;
                grid2.DataBind();
            }


这篇关于在gridview中单击时的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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