Re: How to Bind List<> to GridView with Custom Objects

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



You can just set the DataSource to be a List<MyObject> and DataBind. You
won't get any help with setting up the columns at design time if you do it
that way - you'll have type in all the details. If you want design time
help consider using an ObjectDataSource that points to a method that returns
the list.

Nick



"Jonathan Wood" <jwood@xxxxxxxxxxxxxxxx> wrote in message
news:%238zetMxWIHA.1532@xxxxxxxxxxxxxxxxxxxxxxx
I see that I can create a List<string> list and bind it to a GridView
control (by setting the DataSource property to the list and calling the
DataBind method).

What's the trick to doing the same thing with my own classes instead of a
simple string? Is there an interface or something I can implement so that
the GridView control can detect the properties of my object and display
them ?

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com



.



Relevant Pages

  • Re: Controlling what is regarded as Item/AlternatingItem
    ... from your data + a Hidden flag, and then DataBind from that, so the only ... chased by demons in Gehenna from one room ... the Repeater's DataSource, you will do stuff like use e.Item.ItemIndex-1 ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Datatable as Gridview datasource
    ... Use the old style DataBind() with a DataSource that is set to a ... GridView such as Editing, Deleting and Selecting and make the changes to ... that in turn updates a DataTable that you maintain. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Why cant ms make APIs somewhat compatable
    ... You are the first who calls not the method to databind something well, I never have understood why it was only needed by aspnet. ... There is not any need to set a datasource to nothing in normal ... changed I rebind the second dropdown. ... a notification event that would tell the control to refetch its list. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Setting DatagridView column type as Combo after databind
    ... Create your DataGridView and add 10 columns to it with 3 being ... bound to when you eventually databind the grid. ... DataSource or DataMember properties) set the AutoGenerateColumns ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Why cant ms make APIs somewhat compatable
    ... You are the first who calls not the method to databind something well, I never have understood why it was only needed by aspnet. ... There is not any need to set a datasource to nothing in normal ... changed I rebind the second dropdown. ... a notification event that would tell the control to refetch its list. ...
    (microsoft.public.dotnet.languages.vb)