HeaderTemplate in RadGrid Programmatically

4 posts, 0 answers
  1. Jiju
    Jiju avatar
    57 posts
    Member since:
    Jul 2011

    Posted 21 Nov 2011 Link to this post

     

    Hello

    Can anyone send how to create a header template in GridTemplateColumn programmatically in RadGrid, inorder to set the header context filter menu.

    Thanks in advance.

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Nov 2011 Link to this post

    Hello Jiju,

    Try the following code snippet to create a HeaderTemplate.
    C#:
    protected void grid_ItemCreated(object sender, GridItemEventArgs e)
    {
     if (e.Item is GridHeaderItem)
     {
       GridHeaderItem item = (GridHeaderItem)e.Item;
       Label lbl= new Label();
       lbl.Text = "My text";
       TableCell cell = (TableCell)item["TemplateColumnUniqueName"];
       cell.Controls.Add(lbl);
     }
    }

    -Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. arzie
    arzie avatar
    3 posts
    Member since:
    Apr 2011

    Posted 24 Jul 2012 Link to this post

    one more on the Header Template, I want to give value to a label control in the header radgrid, how do I like the variable 'year'

       <telerik:GridTemplateColumn HeaderText="tes" UniqueName="Rep01"  >
             <HeaderTemplate>
                    <table id="Table1" cellspacing="0" style="width:117px;" class="myTable">
                        <tr>
                            <td colspan="2" align="center">
                                 <b style="font-size: small">
                                    <asp:Label ID="Label1" runat="server" >
                                    </asp:Label>
                                     &nbsp;TARGET
                                 </b>
                            </td>
                        </tr>
                         <tr>
                            <td style="font-size: x-small;" class="style3">BASE TARGET</td>
                            <td style="width: 50%; font-size: x-small;">STRETCH TARGET</td>
                         </tr>
                    </table>
                </HeaderTemplate>
                <ItemTemplate>
                    <table cellspacing="0" width="100%" class="myTable">
                        <tr>
                            <td style="width: 50%">
                                <asp:Label ID="lblltn1" runat="server"
                                    Text='<%# Bind("yearbasetarget","{0:N2}") %>' Width="70px"></asp:Label>
                            </td>
                             <td style="width: 50%">
                                <asp:Label ID="lblelf1" runat="server"
                                     Text='<%# Bind("yearstretchtarget","{0:N2}") %>' Width="70px"></asp:Label>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </telerik:GridTemplateColumn>


    like :
                         2012 Target
      BASE TARGET   STRECTH TARGET
     ---------------------------------------------- 
          0.98                0.92
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Jul 2012 Link to this post

    Hello,

    I suppose you want to show the current date along with the TARGET. Here is the sample code.
    C#:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
       if (e.Item is GridHeaderItem)
       {
           GridHeaderItem item = (GridHeaderItem)e.Item;
           Label lbl = (Label)item.FindControl("Label1");
           lbl.Text=DateTime.Today.Year.ToString();
       }
    }

    Thanks,
    Princy.
Back to Top