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

Get column text server side 2008 Q2

2 Answers 33 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bill Deihl
Top achievements
Rank 2
Bill Deihl asked on 10 Sep 2008, 03:17 PM

 I have a radgid and some of labels on my form.

 I want to get the text of a couple of columns in the selected row and put those values in labels located elsewhere on the form.

 So my question is, what server side event should I use on the radgrd and then how do I get the text value of columns in that row.

 LabelLastName.text = selectedrow.column(“EmployeeLastName”).text

 Thanks for any help!

 Bill

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Sep 2008, 07:23 AM
Hi Bill,

Try the following code snippet to achieve the desired scenario.

CS:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.SelectedItems) 
        { 
            Label1.Text = item["columnUniqueName"].Text.ToString(); 
        } 
    } 



Thanks
Shinu.
0
Accepted
Daniel
Telerik team
answered on 11 Sep 2008, 10:58 AM
Hello Bill,

This is a possible approach:
protected void Page_PreRender(object sender, EventArgs e) 
    if(rgResults.SelectedItems.Count > 0) 
        Label1.Text = ((Label)(RadGrid1.SelectedItems[0] as GridDataItem)["CompanyName"].Controls[1]).Text; 

Yet another approach (DataKeys are used here):
protected void rgResults_ItemCommand(object source, GridCommandEventArgs e) 
    if (e.CommandName == "RowClick"
        Label1.Text = (e.Item as GridDataItem).GetDataKeyValue("ContactName").ToString(); 

Please note that you need to enable postback on row click:
<ClientSettings EnablePostBackOnRowClick="True"

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Bill Deihl
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Daniel
Telerik team
Share this question
or