Solved

DataList help

Posted on 2004-08-18
3
280 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:stewfidgeon
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
nhewitt21 earned 250 total points
ID: 11829841
The only thing i can think of to do this would be to loop through your dataset before you bind it, check if the 'Quantity' exists, if it does np, if it doesn't add it but just make it a null field.

hope this helps


0
 
LVL 1

Author Comment

by:stewfidgeon
ID: 11830089
nHewitt21


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.
0
 
LVL 3

Expert Comment

by:nhewitt21
ID: 11830200
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.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error on link 14 48
free scanner TWAIN can be operated with a Web application 9 63
Where did System.Data.Objects go? 2 29
Sort GridView by ID Descending 1 13
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question