Telerik Radgrid How to add textbox column from code behind

asp.netradgridtelerik

I am adding columns to RadGrid from code behind. In NeedDataSource event, I am binding a DataTable(with 10 columns) to the radgrid.
Everything's working well till here. But I would like to have text boxes in 2 columns(on load itself, not just in edit mode).

<telerik:RadGrid ID="RadGrid1" runat="server" ShowHeader="true" 
        OnNeedDataSource="RadGrid1_NeedDataSource" OnPreRender="RadGrid1_PreRender"
        AutoGenerateColumns="true" >
        <MasterTableView>
        </MasterTableView>
</telerik:RadGrid>

If done declarative, the column definition shall be like this. But I want it accomplished from code behind.

<telerik:GridTemplateColumn HeaderText="Qty">
                <ItemTemplate>
                    <input id="<%# this.GetUniqueId("Qty", Container.DataItem)%>" name="<%# this.GetUniqueId("Qty", Container.DataItem)%>" type="text" value="<%# Eval("Quantity")%>" size="2" maxlength="3"  />
                </ItemTemplate>
</telerik:GridTemplateColumn>

Best Answer

Create TemplateColumn like any other column type and set template object to ItemTemplate (and you can do same for HeaderTemplate and FooterTemplate). But you have to define custom template class witch will implement ITemplate.

You can find an example here :

http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html#Section4

Related Topic