This is a migrated thread and some comments may be shown as answers.

How To Retrieve Data From RadGrid and Placing It In Another Rad grid

2 Answers 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yong
Top achievements
Rank 2
Yong asked on 11 Sep 2008, 09:56 AM
Hi,

I have created two radgrid using data table.

is there any example on which i can refer to which can allow me to retrieve data from the first radgrid and upon clicking a button it will display in the second radgrid table

Thank You

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 11 Sep 2008, 10:57 AM
Hi Yong,

You can check this example for more info:
http://demos.telerik.com/aspnet/Prometheus/Grid/Examples/Programming/SelectedValue/DefaultCS.aspx

In your case you need to handle SelectedIndexChanged event of the first grid and call Rebind() for the second grid which will select desired data source based on SelectedValue of the first grid.

Regards,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Yong
Top achievements
Rank 2
answered on 12 Sep 2008, 01:19 AM
Hi,

Below Are My Code

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;

public partial class Management : System.Web.UI.UserControl
{
    BLLCodeList _bllCL = new BLLCodeList();

    protected void Page_Load(object sender, EventArgs e)
    {
        ConfirmButton.Enabled = false;
        ProductTable.ClientSettings.Selecting.AllowRowSelect = true;
        ProductTable.AllowMultiRowSelection = true;

        if (!IsPostBack)
        {
            ProductTable.DataSource = new DataTable().DefaultView;
            ProductTable.DataBind();

            ConfirmTable.DataSource = new DataTable().DefaultView;
            ConfirmTable.DataBind();
        }
    }

    protected void ProductAddButton_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();

        dt.Columns.Add(new DataColumn("ProdType"));
        dt.Columns.Add(new DataColumn("ProdUnitUser"));

        DataRow dr;

        GridDataItemCollection dtCol = ProductTable.Items;
        foreach (GridDataItem item in dtCol)
        {
            dr = dt.NewRow();
            dr["ProdType"] = item["ProdType"].Text;
            dr["ProdUnitUser"] = item["ProdUnitUser"].Text;
            dt.Rows.Add(dr);
        }

        dr = dt.NewRow();
        dr["ProdType"] = ProdTypeComboBox.SelectedItem.Text.ToString();
        dr["ProdUnitUser"] = ProdUnitUserNumTxtBox.Text.ToString();

        dt.Rows.Add(dr);
        ProductTable.DataSource = dt.DefaultView;
        ProductTable.DataBind();

        ConfirmButton.Enabled = true;


    }

    protected void ConfirmButton_Click(object sender, EventArgs e)
    {
        DataTable dt1 = new DataTable();

        dt1.Columns.Add(new DataColumn("ProdType"));
        dt1.Columns.Add(new DataColumn("ProdUnitUser"));
        dt1.Columns.Add(new DataColumn("ProdAmt"));

        DataRow dr1;

        GridDataItemCollection dtCol1 = ConfirmTable.Items;
        foreach (GridDataItem item in dtCol1)
        {
            dr1 = dt1.NewRow();
            dr1["ProdType"] = item["ProdType"].Text;
            dr1["ProdUnitUser"] = item["ProdUnitUser"].Text;
            dr1["ProdAmt"] = item["ProdAmt"].Text;
            dt1.Rows.Add(dr1);
        }

        dr1 = dt1.NewRow();
        dr1["ProdType"] = ProdTypeComboBox.SelectedItem.Text.ToString();
        dr1["ProdUnitUser"] = ProdUnitUserNumTxtBox.Text.ToString();
        dr1["ProdAmt"] = ProdAmtNumTxtBox.Text.ToString();

        dt1.Rows.Add(dr1);
        ConfirmTable.DataSource = dt1.DefaultView;
        ConfirmTable.DataBind();

        DataTable du = new DataTable();
        ProductTable.DataSource = du;
        ProductTable.DataBind();
    }

    protected void SubmitButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("http://dev1:8080/");
    }

    protected void ProdTypeComboBox_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        if (ProdTypeComboBox.SelectedValue.ToString() == "CopyLog")
        {
            Label1.Text = "Units";
        }
        else
        {
            Label1.Text = "Users";
        }
    }

    protected void ProductTable_DeleteItem(object source, GridCommandEventArgs e)
    {
        DataTable dt = new DataTable();

        dt.Columns.Add(new DataColumn("ProdType"));
        dt.Columns.Add(new DataColumn("ProdUnitUser"));

        DataRow dr;

        GridDataItemCollection dtCol = ProductTable.Items;
        foreach (GridDataItem item in dtCol)
        {
            if (item["ProdType"].Text != e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ProdType"].ToString())
            {
                dr = dt.NewRow();
                dr["ProdType"] = item["ProdType"].Text;
                dr["ProdUnitUser"] = item["ProdUnitUser"].Text;
                dt.Rows.Add(dr);
            }
        }

        ProductTable.DataSource = dt.DefaultView;
        ProductTable.DataBind();
    }

    protected void ConfirmTable_DeleteItem(object source, GridCommandEventArgs e)
    {
        DataTable dt1 = new DataTable();

        dt1.Columns.Add(new DataColumn("ProdType"));
        dt1.Columns.Add(new DataColumn("ProdUnitUser"));
        dt1.Columns.Add(new DataColumn("ProdAmt"));

        DataRow dr1;

        GridDataItemCollection dtCol1 = ProductTable.Items;
        foreach (GridDataItem item in dtCol1)
        {
            if (item["ProdType"].Text != e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ProdType"].ToString())
            {
                dr1 = dt1.NewRow();
                dr1["ProdType"] = item["ProdType"].Text;
                dr1["ProdUnitUser"] = item["ProdUnitUser"].Text;
                dr1["ProdAmt"] = item["ProdAmt"].Text;
                dt1.Rows.Add(dr1);
            }
        }

        ConfirmTable.DataSource = dt1.DefaultView;
        ConfirmTable.DataBind();
    }

}

When i click the confirm button it will retrieve whatever the user has inputted from the product table and display in the confirm table. if the product table has two product, the confirm table will display product 1 + 2.

Any ways?

Tags
Grid
Asked by
Yong
Top achievements
Rank 2
Answers by
Vlad
Telerik team
Yong
Top achievements
Rank 2
Share this question
or