Question

I have a simple use for RadGrid that involves binding it to a list of strings

  i.e. using:  list<string>

The bind works OK and the data displays in the grid. However, the header says "Item", and there are other aspects of the column I'd like to be able to customize. I've tried to set the "DataField" property of the column on the ascx page:

    <telerik:GridTemplateColumn UniqueName="column" 
DataField="" HeaderText="Omniture Codes">

however, it seems to want the name of a data field, as in what you would get with a datatable object, but not with a list.

Does anyone know a way to bind the column to the list, or have another idea for a work-around?

Was it helpful?

Solution

I think you should use a GridBoundColumn instead of the GridTemplateColumn and disable AutoGenerateColumns.

E.g. the following works for me:

ASPX:

<telerik:RadGrid ID="grid" runat="server" AutoGenerateColumns="false">
  <MasterTableView>
    <Columns>
      <telerik:GridBoundColumn DataField="" HeaderText="MyHeaderText">
      </telerik:GridBoundColumn>
    </Columns>
  </MasterTableView>
</telerik:RadGrid>

Code-behind:

protected void Page_Load(object sender, EventArgs e)
{
    List<string> data = new List<string> {"a", "b", "c"};
    grid.DataSource = data;

}

OTHER TIPS

You have to try something like this with the RadGrid:

<Columns>
    <telerik:GridBoundColumn DataField="AddrLine1" HeaderText="Address Line 1" SortExpression="AddrLine1" UniqueName="AddrLine1">
    <HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" Wrap="True" />
    <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"Font-Underline="False" HorizontalAlign="Left" Wrap="True" />
    </telerik:GridBoundColumn>
</Columns>

you may also use Item Template property of radgrid to generate any desgin..

like

<ItemTemplate>
                    <div style="width:277px; text-align:left;">
                        <span style=" font-size:11px;">&nbsp;&nbsp;Tdata1:</span>
                        <%# Eval("data1")%>
                        <br />                        
                        <span>&nbsp;&nbsp;data2:</span>
                        <%# Eval("data2")%>
                        <br />
                    </div>

                </ItemTemplate>
                <Columns>                                           
                <telerik:GridBoundColumn DataField="data1" HeaderText="data1" SortExpression="data1" UniqueName="data1"> 
              </telerik:GridBoundColumn>                            
                <telerik:GridBoundColumn DataField="data2" HeaderText="data2" SortExpression="data2" UniqueName="data2"> 
              </telerik:GridBoundColumn> 
                </Columns>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top