GridTemplateColumn HeaderTemplate

5 posts, 0 answers
  1. archimede
    archimede avatar
    103 posts
    Member since:
    Jul 2006

    Posted 25 Jun 2010 Link to this post

    I have the following grid:
    <telerik:RadGrid ID="RadGridAziendeForUser" runat="server" DataSourceID="ObjectDataSourceAziendeUtente" 
                    EnableEmbeddedSkins="False" GridLines="None" Skin="MachinaWeb" AllowAutomaticUpdates="True" 
                    AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowMultiRowSelection="True" 
                    AutoGenerateEditColumn="True"  
                    OnItemCommand="RadGridAziendeForUser_ItemCommand"
                    <ClientSettings EnablePostBackOnRowClick="True"
                        <Selecting AllowRowSelect="True" /> 
                        <Scrolling EnableVirtualScrollPaging="True" ScrollHeight="200px" /> 
                    </ClientSettings> 
                    <MasterTableView AutoGenerateColumns="False" DataSourceID="ObjectDataSourceAziendeUtente" 
                        EditMode="InPlace" CommandItemDisplay="Top" DataKeyNames="IdUtente,IdAzienda"
                        <CommandItemTemplate> 
                            <div style="float: left;"
                                <asp:LinkButton Text="Nuova Azienda" ID="Insert" runat="server" CommandName="InitInsert" /> 
                            </div> 
                        </CommandItemTemplate> 
                        <RowIndicatorColumn> 
                            <HeaderStyle Width="20px" /> 
                        </RowIndicatorColumn> 
                        <ExpandCollapseColumn> 
                            <HeaderStyle Width="20px" /> 
                        </ExpandCollapseColumn> 
                        <Columns> 
                            <telerik:GridBoundColumn DataField="IdUtente" DataType="System.Int64" HeaderText="IdUtente" 
                                ReadOnly="True" SortExpression="IdUtente" UniqueName="IdUtente" Visible="false"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="IdUtenteAsp" HeaderText="IdUtenteAsp" SortExpression="IdUtenteAsp" 
                                UniqueName="IdUtenteAsp" DataType="System.Guid" Visible="false"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="UserName" HeaderText="UserName" ReadOnly="True" 
                                SortExpression="UserName" UniqueName="UserName" Visible="false"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="IdCultura" DataType="System.Int64" HeaderText="IdCultura" 
                                ReadOnly="True" SortExpression="IdCultura" UniqueName="IdCultura" Visible="false"
                            </telerik:GridBoundColumn> 
                            <telerik:GridTemplateColumn> 
                                <HeaderTemplate> 
                                    <asp:Label ID="Label46" runat="server" Text="Azienda"></asp:Label> 
                                </HeaderTemplate> 
                                <EditItemTemplate> 
                                    <telerik:RadComboBox ID="AziendaRadComboBox" runat="server" DataSourceID="ObjectDataSourceAzienda" 
                                        DataTextField="NomeAzienda" DataValueField="IdAzienda" SelectedValue='<%# Bind("IdAzienda") %>' 
                                        Width="120px" /> 
                                </EditItemTemplate> 
                                <ItemTemplate> 
                                    <asp:Label ID="Label47" runat="server" Width="120px" Text='<%# Bind("Azienda") %>'></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn> 
                                <HeaderTemplate> 
                                    <asp:Label ID="Label48" runat="server" Text="Cultura"></asp:Label> 
                                </HeaderTemplate> 
                                <EditItemTemplate> 
                                    <telerik:RadComboBox ID="CulturaRadComboBox" runat="server" DataSourceID="ObjectDataSourceCultura" 
                                        DataTextField="Cultura" DataValueField="IdCultura" SelectedValue='<%# Bind("IdCultura") %>' 
                                        Width="70px" /> 
                                </EditItemTemplate> 
                                <ItemTemplate> 
                                    <asp:Label ID="Label50" runat="server" Width="70px" Text='<%# Bind("Cultura") %>'></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn> 
                                <HeaderTemplate> 
                                    <asp:Label ID="Label49" runat="server" Text="Gruppo"></asp:Label> 
                                </HeaderTemplate> 
                                <EditItemTemplate> 
                                    <telerik:RadComboBox ID="GruppoRadComboBox" runat="server" DataSourceID="ObjectDataSourceGruppoUtente" 
                                        DataTextField="Nome" DataValueField="IdGruppoUtente" SelectedValue='<%# Bind("IdGruppo") %>' 
                                        Width="120px" /> 
                                </EditItemTemplate> 
                                <ItemTemplate> 
                                    <asp:Label ID="Label51" runat="server" Text='<%# Bind("Gruppo") %>'></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn> 
                                <HeaderTemplate> 
                                    <asp:Label ID="Label52" runat="server" Text="Stabilimento"></asp:Label> 
                                </HeaderTemplate> 
                                <EditItemTemplate> 
                                    <telerik:RadComboBox ID="StabilimentoRadComboBox" runat="server" DataSourceID="ObjectDataSourceStabilimento" 
                                        DataTextField="Denominazione" DataValueField="IdStabilimento" SelectedValue='<%# Bind("IdStabilimento") %>' 
                                        Width="120px" /> 
                                </EditItemTemplate> 
                                <ItemTemplate> 
                                    <asp:Label ID="Label53" runat="server" Text='<%# Bind("Stabilimento") %>'></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn> 
                                <HeaderTemplate> 
                                    <asp:Label ID="Label54" runat="server" Text="Reparto"></asp:Label> 
                                </HeaderTemplate> 
                                <EditItemTemplate> 
                                    <telerik:RadComboBox ID="RepartoRadComboBox" runat="server" DataSourceID="ObjectDataSourceReparto" 
                                        DataTextField="Reparto" DataValueField="IdReparto" SelectedValue='<%# Bind("IdReparto") %>' 
                                        Width="120px" /> 
                                </EditItemTemplate> 
                                <ItemTemplate> 
                                    <asp:Label ID="Label55" runat="server" Text='<%# Bind("Settore") %>'></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" 
                                ConfirmText="Do you really want to delete the selected row?" /> 
                        </Columns> 
                        <EditFormSettings> 
                            <EditColumn> 
                            </EditColumn> 
                        </EditFormSettings> 
                    </MasterTableView><FilterMenu EnableEmbeddedSkins="False"
                    </FilterMenu> 
                    <HeaderContextMenu EnableEmbeddedSkins="False"
                    </HeaderContextMenu> 
                </telerik:RadGrid> 

    I want to access by code the GridTemplateColumn's HeaderTemplate Labels (for example "Label46") to change the Text property. How can I do this in C#?

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

    Posted 25 Jun 2010 Link to this post

    Hello Archimede,

    You can try the following code snippet to access the Label inside HeaderTemplate of GridTemplateColumn.

    C#:
     
     protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridHeaderItem) 
            { 
                GridHeaderItem headerItem = (GridHeaderItem)e.Item; 
                Label lb = (Label)headerItem.FindControl("Label46");  //access Label inside HeaderTemplate 
                lb.Text = "new header"
            } 
        } 

    Thanks,
    Princy.


  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. archimede
    archimede avatar
    103 posts
    Member since:
    Jul 2006

    Posted 25 Jun 2010 Link to this post

    If possible I'd like to make that not in ItemDataBound event (done only one time) for example on RadGrid Init, PreRender or something like that. Is it possible?
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Jul 2010 Link to this post

    Hello Archimede,

     You can achieve the same in PreRender event .

    C#:
     
     protected void RadGrid1_PreRender(object sender, EventArgs e) 
        { 
            GridHeaderItem headerItem = (GridHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0]; 
            Label lb = (Label)headerItem.FindControl("Label46");  //access Label inside HeaderTemplate  
            lb.Text = "new header";  
        } 

    Thanks,
    Princy.



  6. Carlos
    Carlos avatar
    5 posts
    Member since:
    Nov 2008

    Posted 28 Nov 2012 Link to this post

    Excellent solution!
    Thank you!! :)
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017