passing data from one gridvidew to another

May 30 2012 11:01 AM
Hi Friends,

I'm having some issue of passing data from one GridView to another Gridview. Can anyone post some sample links please. Simply i want to pass some selected data from one gridview to another gridview which is in same page. I'm using asp.net 4.0 ,C#. Any code segments are also welcome.

I tried datatable, but it only pick one record always.  see the code below

    DataTable dt = new DataTable();

    void createDT()
    {
        dt.Columns.Add("Product Code", typeof(string));
        dt.Columns.Add("Product Name", typeof(string));
        dt.Columns.Add("Qty", typeof(string));
        dt.Columns.Add("Unit Price", typeof(string));
        isTableCraeted = true;
    }

    bool isTableCraeted= false;
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (isTableCraeted == false)
            createDT();

        string a = GridView1.Rows[0].Cells[1].Text.ToString();
        string b = GridView1.Rows[0].Cells[2].Text.ToString();
        string c = GridView1.Rows[0].Cells[3].Text.ToString();
        string d = GridView1.Rows[0].Cells[4].Text.ToString();
        dt.Rows.Add(a, b, c, d);

        GridView2.DataSource = dt;
        GridView2.DataBind();
       
    }



Thanks
Max

Answers (5)