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

Use SelectRow to convert Grid values to Session Variables

3 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RickC
Top achievements
Rank 1
RickC asked on 18 Mar 2010, 04:30 AM
I need to set up a RadGrid to search a large customer database. Once I have found a particular customer I need to select that RadGrid Row and set the different column values of the Row as Session Variables to be available on another page (this is shopping cart application on the Admin part of the site where Admins can add an order for the customer). I've browsed through a bunch of the documentation but haven't been able to figure out how to do this. Any suggestions?

Rick

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Mar 2010, 09:51 AM
Hi,

You can loop through the items collection in the PreRender event and check for the matching condition e.g. using the DataKeyValue and select the item as shown below:

C#
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridDataItem dataItem in RadGrid1.Items) 
        { 
            if (dataItem.GetDataKeyValue("CustomerID").ToString()=="ALFKI"
            { 
               dataItem.Selected=true;
               Session["Value"]= dataItem["CompanyName"].Text; 
            } 
        } 
     } 

Hope this helps.

Princy
0
RickC
Top achievements
Rank 1
answered on 18 Mar 2010, 06:15 PM
Princy, thanks for the reply. I am not familiar with when the Prerender event occurs in the RadGrid lifecycle but I would assume that it happens before the Grid is rendered so I am not sure how that would allow me to select an existing row from the RadGrad and then access the row values to create Session Variables.

Rick
0
Yavor
Telerik team
answered on 23 Mar 2010, 01:05 PM
Hello Rick,

To see more information on the sequence of events in the control, you can refer to the following article:

http://www.telerik.com/help/aspnet-ajax/grdeventsequence.html

If the PreRender event handler is not a good place for you, you can move the logic to another event

Best wishes,
Yavor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
RickC
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
RickC
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or