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

One grid updating another grid

1 Answer 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DJ
Top achievements
Rank 1
DJ asked on 19 Mar 2009, 08:27 PM
I'm wondering what is the best or easiest way to accomplish the following.

I have 2 RadGrids on a single page.  I want any row click event in RadGrid1 refresh RadGrid2.  I don't have a datasource object on the aspx page, so I need it all to happen in the code behind.  I also need a DataKeyValue from RadGrid1 that I will use when creating the new contents of RadGrid2.

I've seen example of stuff close to this but not exactly this.  I have been trying to get this done with an AjaxManager - but maybe I'm better off not using that?

Any simple examples would be wonderful.  Thanks for the help.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Mar 2009, 04:26 AM
Hello DJ,

You can loop through the rows of the first grid on its SelectedIndexChanged event and check if the row is selected and then retrieve its key value based on which you can populate your second grid.To understand better check out the code below:
cs:
 protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.Items) 
        { 
            if (item.Selected) 
            { 
               string strtxt = item.GetDataKeyValue("ProductName").ToString(); 
               if (strtxt == "Chai"
               { 
                   RadGrid2.DataSource = new string[] {"aa","bb" };//set datasource here 
                   RadGrid2.DataBind(); 
               } 
            } 
        } 
    } 

Thanks
Princy.
Tags
Grid
Asked by
DJ
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or