|
 |
aspx thread: Binding XML to a webform
Message #1 by "Chris Kersey" <ckersey@m...> on Wed, 6 Feb 2002 09:48:05 -0800
|
|
Hi,
I have a function that returns an XML string (type string) and I would like
to bind this string to DataGrid (DataGrid1). Let's say the function looks
like this.
public string ReturnMyXML()
{
return "
<NewDataSet>
<Animal_Table>
<Animal_Id>8</Animal_Id>
<Animal_Name>Byrdie</Animal_Name>
<Type_Of_Animal>Bird</Type_Of_Animal>
</Animal_Table>
<Animal_Table>
<Animal_Id>7</Animal_Id>
<Animal_Name>Tweetie</Animal_Name>
<Type_Of_Animal>Bird</Type_Of_Animal>
</Animal_Table>
</NewDataSet> ";
}
If I have a DataGrid set up (DataGrid1), how can I bind the output of my
function such that the columns will be formatted correctly? I tried the
following, but the Databind method bound each row to each character in the
string...
DataGrid1.DataSource = ReturnMyXML();
DataGrid1.DataBind;
Thanks for any help,
Chris Kersey
----- Original Message -----
From: "Ignacio Varas" <ignacio.varas@n...>
To: "ASP+" <aspx@p...>
Sent: Wednesday, February 06, 2002 4:49 PM
Subject: [aspx] hyperlink navigateurl value
> hi,
> i have a function that retrieves a string that its a url, how can i do
> when i click the hiperlink i call this fuction and take the string into
> navigateurl field?
> thanks in advance
>
Message #2 by "Martin Reeve" <mbreeve@r...> on Thu, 7 Feb 2002 11:40:42
|
|
Chris:
I solved a very similar problem only yesterday. What you require appears
to be something like:
ASCIIEncoding ae = new ASCIIEncoding();
Byte [] byteXML = ae.GetBytes(ReturnMyXML());
MemoryStream stream = new MemoryStream(byteXML);
DataSet dset = new DataSet();
dset.ReadXML(stream);
DataView dview = new DataView(dset.Tables[0]);
DataGrid1.DataSource = dview;
DataGrid1.DataBind();
The first half of this was taken from "Professional XML for .NET
Developers" (bottom p74). The second half was converted from VB.NET taken
from "Professional ASP.NET" (middle and bottom p524).
I personally think that this code shows two very annoying omissions from
the CLS:
(1) The only sensible means of getting an XML string into a
DataSet/DataTable is to convert it to a stream first. (The alternative
would be to write it to a file and read it back again.) Why should this be
the case? You can create a DOM document (XmlDocument) directly from a
string by calling LoadXML(), so why should we not be allowed to create
other objects from an XML string without converting it to a file or to a
stream?
(2) Why can we not deal with a DataTable directly? We seem to have to go
through both a DataSet and a DataView, neither of which is adding any real
value.
If anybody from Microsoft reads this, please could they answer one or
either of these points? Maybe, I'm missing something.
Martin Reeve
> Hi,
>
> I have a function that returns an XML string (type string) and I would
like
> to bind this string to DataGrid (DataGrid1). Let's say the function
looks
> like this.
>
> public string ReturnMyXML()
> {
> return "
> <NewDataSet>
> <Animal_Table>
> <Animal_Id>8</Animal_Id>
> <Animal_Name>Byrdie</Animal_Name>
> <Type_Of_Animal>Bird</Type_Of_Animal>
> </Animal_Table>
> <Animal_Table>
> <Animal_Id>7</Animal_Id>
> <Animal_Name>Tweetie</Animal_Name>
> <Type_Of_Animal>Bird</Type_Of_Animal>
> </Animal_Table>
> </NewDataSet> ";
> }
>
> If I have a DataGrid set up (DataGrid1), how can I bind the output of my
> function such that the columns will be formatted correctly? I tried the
> following, but the Databind method bound each row to each character in
the
> string...
>
> DataGrid1.DataSource = ReturnMyXML();
> DataGrid1.DataBind;
>
> Thanks for any help,
> Chris Kersey
>
>
>
> ----- Original Message -----
> From: "Ignacio Varas" <ignacio.varas@n...>
> To: "ASP+" <aspx@p...>
> Sent: Wednesday, February 06, 2002 4:49 PM
> Subject: [aspx] hyperlink navigateurl value
>
>
> > hi,
> > i have a function that retrieves a string that its a url, how can i do
> > when i click the hiperlink i call this fuction and take the string into
> > navigateurl field?
> > thanks in advance
> >
>
Message #3 by "Chris Kersey" <ckersey@m...> on Thu, 7 Feb 2002 08:59:53 -0800
|
|
I actually tried the 3 step approach like you show below but didn't follow
through since I figured "there MUST be a direct way to get the string into a
dataset or something consumable by a control!". I guess that isn't case
huh?
Thanks Martin, you da bomb! :)
Chris Kersey
----- Original Message -----
From: "Martin Reeve" <mbreeve@r...>
To: "ASP+" <aspx@p...>
Sent: Thursday, February 07, 2002 11:40 AM
Subject: [aspx] Re: Binding XML to a webform
> Chris:
>
> I solved a very similar problem only yesterday. What you require appears
> to be something like:
>
> ASCIIEncoding ae = new ASCIIEncoding();
> Byte [] byteXML = ae.GetBytes(ReturnMyXML());
> MemoryStream stream = new MemoryStream(byteXML);
> DataSet dset = new DataSet();
> dset.ReadXML(stream);
> DataView dview = new DataView(dset.Tables[0]);
> DataGrid1.DataSource = dview;
> DataGrid1.DataBind();
>
> The first half of this was taken from "Professional XML for .NET
> Developers" (bottom p74). The second half was converted from VB.NET taken
> from "Professional ASP.NET" (middle and bottom p524).
>
> I personally think that this code shows two very annoying omissions from
> the CLS:
> (1) The only sensible means of getting an XML string into a
> DataSet/DataTable is to convert it to a stream first. (The alternative
> would be to write it to a file and read it back again.) Why should this be
> the case? You can create a DOM document (XmlDocument) directly from a
> string by calling LoadXML(), so why should we not be allowed to create
> other objects from an XML string without converting it to a file or to a
> stream?
> (2) Why can we not deal with a DataTable directly? We seem to have to go
> through both a DataSet and a DataView, neither of which is adding any real
> value.
>
> If anybody from Microsoft reads this, please could they answer one or
> either of these points? Maybe, I'm missing something.
>
> Martin Reeve
>
>
> > Hi,
> >
> > I have a function that returns an XML string (type string) and I would
> like
> > to bind this string to DataGrid (DataGrid1). Let's say the function
> looks
> > like this.
> >
> > public string ReturnMyXML()
> > {
> > return "
> > <NewDataSet>
> > <Animal_Table>
> > <Animal_Id>8</Animal_Id>
> > <Animal_Name>Byrdie</Animal_Name>
> > <Type_Of_Animal>Bird</Type_Of_Animal>
> > </Animal_Table>
> > <Animal_Table>
> > <Animal_Id>7</Animal_Id>
> > <Animal_Name>Tweetie</Animal_Name>
> > <Type_Of_Animal>Bird</Type_Of_Animal>
> > </Animal_Table>
> > </NewDataSet> ";
> > }
> >
> > If I have a DataGrid set up (DataGrid1), how can I bind the output of my
> > function such that the columns will be formatted correctly? I tried the
> > following, but the Databind method bound each row to each character in
> the
> > string...
> >
> > DataGrid1.DataSource = ReturnMyXML();
> > DataGrid1.DataBind;
> >
> > Thanks for any help,
> > Chris Kersey
> >
> >
> >
> > ----- Original Message -----
> > From: "Ignacio Varas" <ignacio.varas@n...>
> > To: "ASP+" <aspx@p...>
> > Sent: Wednesday, February 06, 2002 4:49 PM
> > Subject: [aspx] hyperlink navigateurl value
> >
> >
> > > hi,
> > > i have a function that retrieves a string that its a url, how can i do
> > > when i click the hiperlink i call this fuction and take the string
into
> > > navigateurl field?
> > > thanks in advance
> > >
> >
>
>
|
|
 |