Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding DataGrid to Arraylist

Status
Not open for further replies.

Fubear

IS-IT--Management
Sep 11, 2002
299
GB
Ok, I have an Arraylist of custom objects, and I want to display these in a dataGrid. I keep getting an error when running the code I have developed.
---
A field or property with the name 'ID' was not found on the selected datasource.
---
My code:
if (myList.Count > 0) {
lblDebug.Text = myList.Count.ToString();
DataGrid1.DataSource = myList;
DataGrid1.DataBind ();
}
//The count is set to 3

<asp:DataGrid id=&quot;DataGrid1&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot;>
<Columns>
<asp:BoundColumn DataField=&quot;ID&quot; HeaderText=&quot;ID&quot;></asp:BoundColumn>
</Columns>
</asp:DataGrid>

---
The custom object does have an ID property, and it is set through the constructor. I also want to display the other properties in the other fields, but I will settle to get just the one working for now.

What am I doing wrong?




 
Ok... I have tried to move over to using a datalist, as that has the functionality i am looking for, I have modified my code slightly as well.

---
My Error:

DataBinder.Eval: 'FH.oMyObj' does not contain a property with the name ID.

---
My Code:

<asp:DataList ID=&quot;MyDataList&quot; Runat=&quot;server&quot;>
<ItemTemplate>
<%# DataBinder.Eval(Container, &quot;DataItem.ID&quot;) %>
</ItemTemplate>
</asp:DataList>

public class oMyObj {
public String ID;
...
---
As you can see, my Object DOES have the property, and that the compiler is correctly identifying which type of object is in there.

Pulling my hair out over this one.
---
 
Take a look at

aspnet.4guysfromrolla.com/articles/102303-1.2.aspx

Not quite the same, but similar in what they are trying to do.

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top