XML DATA source DataSetDataSource DataMemeber

  • Thread starter Thread starter mo
  • Start date Start date
M

mo

Hi,

I have a DataSetDataSource populated from an XML datasource.
DataMember is assigned to one of the datasets in the XML file. I have
a DataList which is displaying the DataSetDataSource. Any idea on how
to get the DataSetDataSource inlcude multiple datasets within the XML
files?

Here is the a part of XML file

- <image>
<title>Yahoo! News</title>
<width>142</width>
<height>18</height>
<link>http://xxx.xxx.com/</link>
</image>
- <item>
<title>xxxxxxxxxxxxxxxx</title>
<pubDate>Fri, 19 Nov 2004 21:33:12 GMT</pubDate>
</item>

if I have my DataSetDataSource have "Item" or "image", my datalist
display's the item. but I can not have my datalist to include both
fields in the display.
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" Runat="server"
NavigateUrl='<%# Bind("link") %>' Text='<%# Bind("title")
%>'></asp:HyperLink>
</ItemTemplate>
Any ideas is greatly appreciated.

Thanks,
Mo
 
I'm a little confused because I'm familiar with "DataSet" objects and also
"DataList" objects, which have a property named "DataSource", but I don't
think there's anything called a "DataSetDataSource".

I'm also not sure what you mean when you say that your XML file has DataSets
in it because I though a DataSet was a container for XML data, not the other
way around.

Be that as it may, I think part of the problem is that your DataSet has two
DataTables in it. One of them must be called "image" and the other one is
called "item". When binding the DataList, you set the DataSource property to
the DataSet and the DataMember to the name of one of those tables. But in
our own ways, we both seem to come to the conclusion that you can't bind to
two tables at onse.

Solutions? Here's two possibilities to research:

1) Construct a schema for your dataset that forces <image> and <item> to be
two columns within the same DataTable. Set DataSource to the DataSet and
DataMember to the name of that one table. You should be good to go.

2) Construct a new class that has at least two public peoperties, call them
"image" and "item". Write code that reads through the XML data (or the
dataset) and instantiates a series of these objects. Add each of these
objects to an ArrayList. Set the DataSource of your DataList to that
ArrayList. (ArrayLists implement IEnumerable. You can bind a DataList to
any object that implements IEnumerable.)

Good Luck
 
Back
Top