I have the following classes (pseudocode):
If I set ItemDetail as the datasource for an asp.net gridview:
grid.DataSource = new List<ItemDetail>();
grid.DataBind();
Can I use Field1 in the GridView? If so, what is the correct DataBinder syntax? The following code blows up trying to cast to an Item:
<%# DataBinder.Eval(Container.DataItem, "Field1") %>
Thanks in advance for any help.
EDIT: And I'm a moron. I had copied the gridview and was calling a RowDataBound event handler for a different grid... Sorry to have wasted everyones time, but there is some good info here regardless if anyone has the same question. In the end, the public properties of the base class are binding correctly. Thanks!
If your base class property is public, you shouldn't have an issue as long as you're also initializing it in your child constructors.
Also, I'm not sure if your example binding is pseudocode or not, but you have to bind a grid to an IListSource, IEnumerable, or IDataSource, so you need a Collection, List, IQueryable, etc. of ItemDetails.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With