Radgrid header template - how access the controls in javascript

5 posts, 0 answers
  1. Boris
    Boris avatar
    21 posts
    Member since:
    Jun 2009

    Posted 04 Apr 2011 Link to this post

    Dear Sirs!
    I do know how access the controls in ItemTemplate of RadGrid.
    But I cannot access the controls in HeaderTemplate!.

    Can you help me?

    Thank you very much in advance

    Boris
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Apr 2011 Link to this post

    Hello Boris,
    One approach is to save the HeaderTemplate control ID in the Hidden Field and from the ItemCreatedEvent, and then access the TextBox using the HiddenField value. Here is a sample code.
    aspx:
    <telerik:GridTemplateColumn  . . . . . . . . . >
         <HeaderTemplate>
               <asp:TextBox ID="TextBox1" runat="server" Text="Text"></asp:TextBox>
          </HeaderTemplate>
    </telerik:GridTemplateColumn>

    C#:
    protected void rad_ItemCreated(object sender, GridItemEventArgs e)
     {
         if (e.Item is GridHeaderItem)
         {
             GridHeaderItem hItem = (GridHeaderItem)e.Item;
             TextBox txt1 = (TextBox)hItem.FindControl("TextBox1");
             HiddenField1.Value = txt1.ClientID.ToString();
         }
     }

    Client side:
    function ButtonClick()// accessing the HeaderTemplate TextBox value from external Button click.
      {
          var hidden = document.getElementById("HiddenField1");
          var txtBox = document.getElementById(hidden.value);
          alert(txtBox.value);
      }

    Thanks,
    Shinu.
  3. Boris
    Boris avatar
    21 posts
    Member since:
    Jun 2009

    Posted 04 Apr 2011 Link to this post

    Hello Shinu,
    This is OK but it is not-applicable for me because I build the RadGrid dynamically and I don't know before the count of my template columns.

    I would like know - if does exist the client API function that allows to get the header of teh grid and after with the help of findControl (or findElement) to find my needed text box in the header. I do know ID of this text box.

    Thank you very much!

    Boris 
  4. Tsvetina
    Admin
    Tsvetina avatar
    2481 posts

    Posted 07 Apr 2011 Link to this post

    Hello Boris,

    From what I see, Shinu's approach does not require knowing the number of template columns in your grid.

    You only need to know the server ID of the TextBox in question. The GridHeaderItem is the whole grid header, not a separate cell from it. As long as the textboxes in the different header templates have different IDs, it should be fine to use this approach.

    There is no separate property or method for accessing the grid header. You can access its html element using jQuery but this would not help a lot as you want to then access controls inside it.

    Regards,
    Tsvetina
    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
  5. Boris
    Boris avatar
    21 posts
    Member since:
    Jun 2009

    Posted 07 Apr 2011 Link to this post

    Hello Tsvetina,

    Thank you very much for the answer.

    I have used already this approach!

    Thank tou for your attendance!

    Boris
Back to Top