Search code examples
asp.netteleriktelerik-grid

RadGrid - How do you change HeaderText of Bound field?


I am using a RadGrid and I had the autogenerated set to true. This results in a column header text of the the database field cap_name. In an ASP.NET GridView you would change it like (after setting autogeneratedcolumns to false:

<Columns>
         <asp:BoundField DataField="cap_name" HeaderText="Capability" 
            SortExpression="cap_name" />
    </Columns>

I set autogenerated colums to false and tried to use BoundField but the compiler said to use telerik:GridColumn. How do I use this to get a similar result?


Solution

  • Use <rad:GridBoundColumn HeaderText="Capability" UniqueName="ClmCapability" DataField="cap_name" /> .

    NOTE : replace <rad: with the prefix you use for your RadGrid control when you register it. You can find it as TagPrefix in :

    <%@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>
    

    You can't use asp:boundfield because it is for asp.net gridview, while you are using telerik radgrid

    EDIT :

    <rad:RadGrid ID="MyRadGrid" runat="server" EnableAJAXLoadingTemplate="true"  
                AutoGenerateColumns="false" AllowFilteringByColumn="True" AllowPaging="True"
                AllowSorting="True" GridLines="None" Width="60%" EnableAJAX="True" OnNeedDataSource="MyRadGrid_NeedDataSource">
                <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">
                </ClientSettings>
                <MasterTableView RetrieveAllDataFields="false" AdditionalDataFieldNames="Name">
                    <PagerStyle AlwaysVisible="false" Mode="NextPrevNumericAndAdvanced" ShowPagerText="true" />
                    <Columns>
    
                        <rad:GridBoundColumn HeaderText="Capability" UniqueName="ClmCapability" DataField="cap_name" />
    
                    </Columns>
                </MasterTableView>
            </rad:RadGrid>