Solved

DataList help

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2013 debugging 2 35
New to SOAP and need some direction 10 47
Connection String 16 43
Reset asp.net login password 4 34
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

21 Experts available now in Live!

Get 1:1 Help Now