Getting adjacent Cell Values in a radgrid with templated columns

2 posts, 0 answers
  1. MarkSci
    MarkSci avatar
    16 posts
    Member since:
    Dec 2011

    Posted 11 Jan 2012 Link to this post


    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
  2. Andrey
    Andrey avatar
    836 posts

    Posted 13 Jan 2012 Link to this post


    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.

    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
Back to Top