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

[Solved] Changing RadGrid Header Template Text at Runtime

3 Answers 664 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sourab
Top achievements
Rank 1
Sourab asked on 25 Mar 2009, 10:46 AM
Hi all,

I have a requirement to change the header text at runtime.
I have one gridtemplate column like the following:

 <radG:GridTemplateColumn DataField="id" HeaderText="ID" SortExpression="id"
                        UniqueName="id">
                       
                        <EditItemTemplate >
                            <asp:TextBox ID="Txtid" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"Id") %>' style="position: static" OnTextChanged="Txtid_TextChanged" AutoPostBack="true"></asp:TextBox>
                            <asp:ImageButton ID="MediaIDLookup" runat="server" BorderStyle="Solid"
                                Height="18px" ImageUrl="~/Images/magnifier.gif" Style="position: static" Width="21px" OnClick="IDLookup_Click" />
                     
                            </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Lblid" runat="server" Width="120px" Text='<%# DataBinder.Eval(Container.DataItem,"Id") %>'></asp:Label>
                        </ItemTemplate>
                        <HeaderStyle ForeColor="Black" />
                    </radG:GridTemplateColumn>

when i click the image button, a new web page opens , i get the value from new page and i need to change the header text of the id column to new value that i picked from new page.

Pls advice how to do that.

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 30 Mar 2009, 08:09 AM
Hello Sourab,

For example you can modify the header item on Page_PreRender:
protected void Page_PreRender(object o, EventArgs e) 
    GridHeaderItem headerItem = RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem; 
    headerItem["myTemplateColumn"].Text = "MODIFIED"

Regards,
Daniel
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Clive Hoggar
Top achievements
Rank 1
answered on 14 Sep 2009, 04:54 PM
HiI

I am using a vb version of this with the same gridtemplate column scenario, but I can't get it to to actually change the
column header text. The only thing I can think of is that the grid is within a RadAjaxPanel. Is this a problem
for this method? Can someone advise how do I get round it?


Protected Sub Page_PreRender(ByVal o As Object, ByVal e As EventArgs)  
        Dim headerItem As GridHeaderItem = TryCast(RadGrid1.MasterTableView.GetItems(GridItemType.Header)(o), GridHeaderItem)  
        headerItem("PricePerBottle").Text = "test" 
    End Sub 

The page has a MasterPage but there are no grids in the MasterPage to confuse things.

Thanks

Clive

P.S I assume the '0' in the code should be 'o' but I tried it with both anyway
0
Shinu
Top achievements
Rank 2
answered on 15 Sep 2009, 05:47 AM
Hi Clive,

The above given code must be working fine. Can you confirm whether the RadGrid ID that you have specified in the code behind is same as that mentioned in the aspx declaration.

You may also give a try with the following code approach and see if it works.

VB:
 
 
    Protected Sub Page_PreRender(ByVal o As ObjectByVal e As EventArgs) 
        
        For Each headerItem As GridHeaderItem In RadGrid1.MasterTableView.GetItems(GridItemType.Header) 
            headerItem("PricePerBottle").Text = "MODIFIED" 
            
        Next 
    End Sub 


Thanks
Shinu
Tags
Grid
Asked by
Sourab
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Clive Hoggar
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or