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

[Solved] controls of template column header

1 Answer 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Frank Whittaker
Top achievements
Rank 1
Frank Whittaker asked on 03 Dec 2009, 03:21 AM
Hi,

I have trouble to access the controls which are in template column header.  Please advice how I can get the controls.

Cheers

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Dec 2009, 04:50 AM
Hi Frank,

Try the following code snippet in order to access the control placed in 'HeaderTemplate' of GridTemplateColumn.

aspx:
 
 <telerik:GridTemplateColumn UniqueName="TempCol"
    <HeaderTemplate> 
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
    </HeaderTemplate> 
    <ItemTemplate> 
 
    </ItemTemplate> 
    </telerik:GridTemplateColumn> 

cs:
 
    protected void Button4_Click(object sender, EventArgs e) 
    { 
        GridHeaderItem headerItem = (GridHeaderItem)RadGrid1.MasterTableView.GetItems( GridItemType.Header)[0]; 
        TextBox textBox1 = (TextBox)headerItem.FindControl("TextBox1"); 
        textBox1.Text = "hi";  // Change the text 
    } 

Here is the code if you want to access the control in ItemDataBound event.
cs:
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridHeaderItem) 
        { 
            GridHeaderItem headerItem = (GridHeaderItem)e.Item; 
            TextBox textBox1 = (TextBox)headerItem.FindControl("TextBox1"); 
            textBox1.Text = "hi";          
        } 
    } 

-Shinu.
Tags
Grid
Asked by
Frank Whittaker
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or