ASPxGridView -- How to simply add example values with only a DataSource property?

Earlz picture Earlz · May 20, 2010 · Viewed 10.2k times · Source

Hello I have a ASPxGridView. In it(for the uninformed) is only a DataSource property for telling it what data to load. My problem is that I'm simply trying to mock up an example and don't need to tie it to an actual database. How would I do this? I basically just want a few rows and some columns but since it only takes a datasource I'm not sure how to do it. Would ObjectDataSource be what I'm looking for?

Answer

alejandrobog picture alejandrobog · May 20, 2010

Just set the datasource to a list of anything like this:

public class Item
{
  public string Name { get; set; }
  public int Count { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
  GridView1.DataSource = new Item[] { new Item { Name = "2", Count = 2 }, new Item { Name = "3", Count = 3 }, };
  GridView1.DataBind();
}


<dxwgv:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" Width="100%" AutoGenerateColumns="False" >
     <Columns>
         <dxwgv:GridViewDataTextColumn Caption="Name" FieldName="Name" ReadOnly="True">
         </dxwgv:GridViewDataTextColumn>
         <dxwgv:GridViewDataTextColumn Caption="Count" FieldName="Count" ReadOnly="True" >
         </dxwgv:GridViewDataTextColumn>
     </Columns>
     </dxwgv:ASPxGridView>