Solved

DataList help

Posted on 2004-08-18
3
275 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now