Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
Unareshraju 1-Aug-12 2:16am    
hi bhaskar,

to create an object for a checkboxes (create in global.cs)
we can possible to pass the object between pages in a project.
Sandeep Mewara 1-Aug-12 2:45am    
What have you tried so far? Where are you stuck?

Hi,
Try this:
In 1st page:
C#
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:
C#
DataTable dt =new DataTable();
//Getting the data form sessoin
dt = Session["SelRows"] as DataTable;
if(dt != null)
{
    grid2.DataSource = dt;
    grid2.DataBind();
}




All the best.
--Amit
 
Share this answer
 
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();
            }
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900