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

10,365

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>
Share:
10,365
Earlz
Author by

Earlz

Hello there! My name's Jordan Earls, but most people online know me as "earlz". I'm the lead developer and a co-founder of the Qtum project which brings the Ethereum Virtual Machine (ie, the thing that makes Solidity contracts function) to a UTXO based blockchain similar to Bitcoin. I've been programming since I was 13 and am completely self-taught. Low-level code like assembly and pointer arithmetic is the fun stuff for me. I also make music when I have time even though it's usually awful. Most of my personal projects are open source and BSD licensed. The majority of them are at bitbucket with the rest of them being listed on github Also, you can follow me on the twitters @earlzdotnet

Updated on June 05, 2022

Comments

  • Earlz
    Earlz almost 2 years

    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?

  • Earlz
    Earlz almost 14 years
    Ok but the columns are not auto-generated. How do you get this method to work with thaT?
  • alejandrobog
    alejandrobog almost 14 years
    Sorry i just find out that there is a control named APSxGrid I thought you were refering to the standard asp Gridview
  • Earlz
    Earlz almost 14 years
    @alen yea it's different but actually it descends from the regular ASP.Net GridView so your advice may help. It does actually recognize the rows and such using your code(will generate 2 rows) but I can't get it to map Name and Count to columns
  • Earlz
    Earlz almost 14 years
    @alen wow ASPx stuff and you don't even know it! This did it though! It was the FieldName property that was missing from your initial code mainly. Now it works though. Thanks!