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

Getting adjacent Cell Values in a radgrid with templated columns

1 Answer 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
MarkSci
Top achievements
Rank 1
MarkSci asked on 11 Jan 2012, 10:14 AM
Hello,

I have a radgrid which contains 2 templated columns each containing a button and a label. When the buttons are clicked, a modal radWindow is displayed allowing the user to select a value which, once the window is closed, is displayed within the label next to the button that was clicked within the templated column. Importantly the value at this point has not been saved to a database.

When the button in the second templated column is clicked, I need to be able to pass the value in the label from the first templated column to the modal radWindow as this value affects the list of available values which are displayed in that radWindow.

How do I get the value from the label in the first templated column when the button in the second templated column is clicked? I have tried setting a custom attribute (which works fine if the value originates from the database) however if I update the label and try setting the attribute using javascript (below), the value is not retained.

objLookupCellLabel.childNodes[0].setAttribute("clientcode", Code);

Many thanks

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 13 Jan 2012, 03:13 PM
Hello,

You could achieve your goal by getting the naming container of the button and cast it as GridDataItem. Then with help of the FindControl method you could find the Label control and access its Text property to get the value. You could use the following code to achieve this:

protected void Button1_Click(object sender, EventArgs e)
{
    Button button = sender as Button;
    GridDataItem dataItem = button.NamingContainer as GridDataItem;
    Label label = dataItem["TemplateColumn1UniqueName"].FindControl("LabelControlID") as Label;
    label.Text = "Text changed!";       
}

Give this approach a try and check whether this is the desired behavior.

Regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
MarkSci
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or