Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding Telerik RadGRID to a list<string> object

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?

like image 384
alchemical Avatar asked Dec 14 '22 05:12

alchemical


1 Answers

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;

}
like image 141
M4N Avatar answered Dec 29 '22 10:12

M4N