Trouble referencing control found in GridTemplateColumn HeaderTemplate Collection

2 posts, 0 answers
  1. J
    J avatar
    143 posts
    Member since:
    Jun 2006

    Posted 18 Aug 2011 Link to this post

    I have the following RadGrid:
    <telerik:RadGrid ID="DocumentGrid1" runat="server" AutoGenerateColumns="false" AllowSorting="True"
    AllowMultiRowSelection="false" HorizontalAlign="Center" AllowPaging="True" EnableEmbeddedSkins="False"
    Skin="TDocs" PageSize="7" AllowAutomaticDeletes="false" AllowAutomaticUpdates="false"
    AllowAutomaticInserts="false" ClientSettings-Selecting-AllowRowSelect="true"
    AlternatingItemStyle-BackColor="White" ClientSettings-EnableRowHoverStyle="false"
    OnItemDataBound="DocumentGrid1_ItemDataBound" OnNeedDataSource="DocumentGrid1_NeedDataSource"
    OnItemCommand="DocumentGrid1_ItemCommand" ToolTip="Please click a row on the grid to perform an action.">
    <MasterTableView DataKeyNames="FK" DataMember="s" HeaderStyle-ForeColor="White"
        PagerStyle-Mode="NextPrevNumericAndAdvanced">
        <Columns>
            <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Associated s"
                HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="true">
                <HeaderTemplate>
                    <table class="Table" cellpadding="0" cellspacing="0" width="90%">
                        <tr>
                            <td width="13%" style="background-color: #CCCCCC; border-right: #000000 1px solid;">
                                <asp:LinkButton ID="ID" runat="server"
                                        CommandName="Sort" CommandArgument="ID" 
                                        Text="ID" OnClick="HeaderSort_Click"
                                        ></asp:LinkButton>
                                           
                                        <asp:Label id="lblIDSort" runat="server" Text="" />
                            </td>
                        </tr>
                    </table>
                </HeaderTemplate>
                <ItemTemplate>
                <table class="TableCRM" cellpadding="0" cellspacing="0" width="90%">
                    <tr>
                        <td width="13%" rowspan="4" align="center" style="border-right: #000000 1px solid;">
                            <asp:Label ID="lblMID" runat="server" CssClass="RowCells" Visible="false"></asp:Label>
                            <asp:Label ID="lblID" runat="server" CssClass="RowCells"></asp:Label>
                        </td>
                    </tr>
                        </table>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings EnablePostBackOnRowClick="false">
    </ClientSettings>
    </telerik:RadGrid>

    When I fire the event HeaderSort_Click, how do I reference the Label 'lblIDSort' that is in the HeaderTemplate column?

    Here is my code behind:
    protected void HeaderSort_Click(object sender, EventArgs e)
    {
       LinkButton lb = sender as LinkButton;
       string CommandArgument = lb.CommandArgument.ToString();
    }


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

    Posted 19 Aug 2011 Link to this post

    Hello,

    You can access the Label control in HeaderTemplate as shown below.
    C#:
    protected void HeaderSort_Click(object sender, EventArgs e)
    {
     LinkButton link = (LinkButton)sender;
     Label lbl = (Label)link.FindControl("lblIDSort");
    }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top