stewfidgeon
asked on
DataList help
Hi,
I have a DataList control to which I am binding a DataSet generated from an XML File.
The file structure is usually fixed, however, on occasion some Elements get missed from the document.
When I do the databinding, I (obviously) get the following error:
DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with the name Quantity
The line of code in the template causing the problem being:
<asp:label id=Label15 runat="server" font-size="10" Text='<%# DataBinder.Eval(Container, "DataItem.Quantity") %>'></asp:label>
What I'd like to know is:
a) Can I make some of the databound items optional, so if they are not present in the dataset they simply dont get bound?
b) Is there any other work around for this?
Theres a lot of fields in this document (30+) so I'd really rather not have to check for them individually if possible.
Cheers,
Stew
I have a DataList control to which I am binding a DataSet generated from an XML File.
The file structure is usually fixed, however, on occasion some Elements get missed from the document.
When I do the databinding, I (obviously) get the following error:
DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with the name Quantity
The line of code in the template causing the problem being:
<asp:label id=Label15 runat="server" font-size="10" Text='<%# DataBinder.Eval(Container,
What I'd like to know is:
a) Can I make some of the databound items optional, so if they are not present in the dataset they simply dont get bound?
b) Is there any other work around for this?
Theres a lot of fields in this document (30+) so I'd really rather not have to check for them individually if possible.
Cheers,
Stew
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks i understand, its a hard one this.
i have been looking for ways to optionally bind columns for a while but i've not found anything at all, yet.
i have been looking for ways to optionally bind columns for a while but i've not found anything at all, yet.
ASKER
Thanks for that mate. I appreciate the help.
What I've done as a work around is pretty similar. Ive created a string with all possible column names in it (theres about 40 possibilities), and split that into an array.
I check each string value in the array to see if the column exists. If it does, I dont do anything, if it doesnt, then I create a column of the same name, set the default value to "N/A", and add the column.
In the absence of any answers letting me optionally bind columns if the data exists, I'll accept your answer by the end of the day.