Can you bind an asp.net binding to a field in the base class?

I have the following classes (pseudocode):

  • Element (int Field1)
  • ItemDetail: Item (int Field2, field string3)

If I set ItemDetail as the data source for gridview asp.net:

grid.DataSource = new List<ItemDetail>();
grid.DataBind();

Can I use Field1 in a GridView? If so, what is the correct DataBinder syntax? The following code explodes, trying to apply to an element:

<%# DataBinder.Eval(Container.DataItem, "Field1") %>

Thanks in advance for your help.

EDIT: And I'm a moron. I copied gridview and called the RowDataBound event handler for another grid ... Sorry to waste it all the time, but there is some good information here, regardless of whether anyone has the same question. As a result, the public properties of the base class are properly bound. Thank!

+5
2

, , .

, , , IListSource, IEnumerable IDataSource, , , IQueryable .. ItemDetails.

+1

, ItemDetail , Field1. , .

<%# DataBinder.Eval(Container.DataItem, "Field1") %>

ItemDetal itemDetail = new ItemDetail();
itemDetail.Field1 = 100;
  • Field1 - accessable, . 100 .
-1

All Articles