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

HeaderTemplate in RadGrid Programmatically

3 Answers 412 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jiju
Top achievements
Rank 1
Jiju asked on 21 Nov 2011, 08:00 AM

 

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.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Nov 2011, 08:16 AM
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.
0
arzie
Top achievements
Rank 1
answered on 24 Jul 2012, 07:29 AM
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
0
Princy
Top achievements
Rank 2
answered on 24 Jul 2012, 10:05 AM
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.
Tags
Grid
Asked by
Jiju
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
arzie
Top achievements
Rank 1
Share this question
or