By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,971 Members | 907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,971 IT Pros & Developers. It's quick & easy.

Rookie question : Writing edited form data (gridview) to XML

P: n/a
using Visual Studio 2005

C# ASP.NET

I know there has to be a simple way to do this....I want to use C# in a code
behind for aspx.

Populate a GridView from an xml file

Add Fields to the GridView to allow entry of quantity and Y/N switch for
each row

Write contents of GridView to new xml file.

Example...

xml file that populates gridview cols:

<items>
<item id=1>
<name="Bread" />
<price="1.10" />
</item>
<item id=2>
<name="Milk" />
<price="2.20" />
</item>
<item id=3>
<name="Cookies" />
<price="3.30" />
</item>
</items>

Grid View shows:

Bread 1.10 (textboxQuantity = 3)
Milk 2.20 (textboxQuantity = 6)
Cookies 3.30 (textboxQuantity = 9)
new xml file output should look like:

<items>
<item id=1 quantity=3 price=1.10 />
<item id=2 quantity=6 price=2.20 />
<item id=3 quantity=9 price=3.30 />
</items>
Thanks.
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Some of these steps should be pretty casual, others I am not sure because I
have not worked on GridView in a while.

Your first step "Populate a GridView from an xml file" could be a simple as
databinding the GridView control to an XmlDataSource control (if you are
using GridView you must be using a Whidbey, therefore the data source
controls are also available). You can do this programmatically in the code
behind if you have to (there are some limited samples on this somewhere), or
use VS.NET to do it declaratively on the ASPX page.

"Add Fields to the GridView".... you should be able to do this
programmatically, too, check out the samples for GridView in the docs. You
might have to add these fields specifically after a databound event signals
that the GridView is populated, but before render time..?

"Write contents of GridView to new xml file". I assume you mean on postback,
right? read below...

If writing the Gridview to a new xml file, and not persisting changes to the
file you loaded from is the real goal, you might go about this whole
scenario like a little differently. Maybe load a DataSet in memory from an
XML file. Add columns to the DataSet that represent the extra fields you
want the GridView to display, perhaps add fields to GridView pre-render?
Databind the GridView to the DataSet. Finally, on post-back, save the
DataSet and any of its changes to a new XML file. The DataSet might make the
transform to and from different XML files (and schemas, effectively, since
you are adding columns of data) a bit easier.

HTH, Alex

"theKirk" <th*****@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com...
using Visual Studio 2005

C# ASP.NET

I know there has to be a simple way to do this....I want to use C# in a
code
behind for aspx.

Populate a GridView from an xml file

Add Fields to the GridView to allow entry of quantity and Y/N switch for
each row

Write contents of GridView to new xml file.

Example...

xml file that populates gridview cols:

<items>
<item id=1>
<name="Bread" />
<price="1.10" />
</item>
<item id=2>
<name="Milk" />
<price="2.20" />
</item>
<item id=3>
<name="Cookies" />
<price="3.30" />
</item>
</items>

Grid View shows:

Bread 1.10 (textboxQuantity = 3)
Milk 2.20 (textboxQuantity = 6)
Cookies 3.30 (textboxQuantity = 9)
new xml file output should look like:

<items>
<item id=1 quantity=3 price=1.10 />
<item id=2 quantity=6 price=2.20 />
<item id=3 quantity=9 price=3.30 />
</items>
Thanks.

Nov 12 '05 #2

P: n/a
Yep that sounds like the way to do it!!!

Thanks!

"Alex Krawarik [MSFT]" wrote:
Some of these steps should be pretty casual, others I am not sure because I
have not worked on GridView in a while.

Your first step "Populate a GridView from an xml file" could be a simple as
databinding the GridView control to an XmlDataSource control (if you are
using GridView you must be using a Whidbey, therefore the data source
controls are also available). You can do this programmatically in the code
behind if you have to (there are some limited samples on this somewhere), or
use VS.NET to do it declaratively on the ASPX page.

"Add Fields to the GridView".... you should be able to do this
programmatically, too, check out the samples for GridView in the docs. You
might have to add these fields specifically after a databound event signals
that the GridView is populated, but before render time..?

"Write contents of GridView to new xml file". I assume you mean on postback,
right? read below...

If writing the Gridview to a new xml file, and not persisting changes to the
file you loaded from is the real goal, you might go about this whole
scenario like a little differently. Maybe load a DataSet in memory from an
XML file. Add columns to the DataSet that represent the extra fields you
want the GridView to display, perhaps add fields to GridView pre-render?
Databind the GridView to the DataSet. Finally, on post-back, save the
DataSet and any of its changes to a new XML file. The DataSet might make the
transform to and from different XML files (and schemas, effectively, since
you are adding columns of data) a bit easier.

HTH, Alex

"theKirk" <th*****@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com...
using Visual Studio 2005

C# ASP.NET

I know there has to be a simple way to do this....I want to use C# in a
code
behind for aspx.

Populate a GridView from an xml file

Add Fields to the GridView to allow entry of quantity and Y/N switch for
each row

Write contents of GridView to new xml file.

Example...

xml file that populates gridview cols:

<items>
<item id=1>
<name="Bread" />
<price="1.10" />
</item>
<item id=2>
<name="Milk" />
<price="2.20" />
</item>
<item id=3>
<name="Cookies" />
<price="3.30" />
</item>
</items>

Grid View shows:

Bread 1.10 (textboxQuantity = 3)
Milk 2.20 (textboxQuantity = 6)
Cookies 3.30 (textboxQuantity = 9)
new xml file output should look like:

<items>
<item id=1 quantity=3 price=1.10 />
<item id=2 quantity=6 price=2.20 />
<item id=3 quantity=9 price=3.30 />
</items>
Thanks.


Nov 12 '05 #3

P: n/a
One thing to keep in mind is that if you go the DataSet way, you can no
longer use a datasource control and will have to handle all the events
yourself, which is Everett-style, not Whidbey-style data binding. Instead,
on postback you can get the XmlDocument from the XmlDataSource you bind to
initially using GetXmlDocument() mehod, mess around in it anyway you want
including adding nodes using the std System.Xml APIs, and call Save() on it
when you are ready.

So there are def a couple of different ways to go, all depending on exactly
whats going on with your scenario.
"theKirk" <th*****@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com...
Yep that sounds like the way to do it!!!

Thanks!

"Alex Krawarik [MSFT]" wrote:
Some of these steps should be pretty casual, others I am not sure because
I
have not worked on GridView in a while.

Your first step "Populate a GridView from an xml file" could be a simple
as
databinding the GridView control to an XmlDataSource control (if you are
using GridView you must be using a Whidbey, therefore the data source
controls are also available). You can do this programmatically in the
code
behind if you have to (there are some limited samples on this somewhere),
or
use VS.NET to do it declaratively on the ASPX page.

"Add Fields to the GridView".... you should be able to do this
programmatically, too, check out the samples for GridView in the docs.
You
might have to add these fields specifically after a databound event
signals
that the GridView is populated, but before render time..?

"Write contents of GridView to new xml file". I assume you mean on
postback,
right? read below...

If writing the Gridview to a new xml file, and not persisting changes to
the
file you loaded from is the real goal, you might go about this whole
scenario like a little differently. Maybe load a DataSet in memory from
an
XML file. Add columns to the DataSet that represent the extra fields you
want the GridView to display, perhaps add fields to GridView pre-render?
Databind the GridView to the DataSet. Finally, on post-back, save the
DataSet and any of its changes to a new XML file. The DataSet might make
the
transform to and from different XML files (and schemas, effectively,
since
you are adding columns of data) a bit easier.

HTH, Alex

"theKirk" <th*****@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com...
> using Visual Studio 2005
>
> C# ASP.NET
>
> I know there has to be a simple way to do this....I want to use C# in a
> code
> behind for aspx.
>
> Populate a GridView from an xml file
>
> Add Fields to the GridView to allow entry of quantity and Y/N switch
> for
> each row
>
> Write contents of GridView to new xml file.
>
> Example...
>
> xml file that populates gridview cols:
>
> <items>
> <item id=1>
> <name="Bread" />
> <price="1.10" />
> </item>
> <item id=2>
> <name="Milk" />
> <price="2.20" />
> </item>
> <item id=3>
> <name="Cookies" />
> <price="3.30" />
> </item>
> </items>
>
> Grid View shows:
>
> Bread 1.10 (textboxQuantity = 3)
> Milk 2.20 (textboxQuantity = 6)
> Cookies 3.30 (textboxQuantity = 9)
>
>
> new xml file output should look like:
>
> <items>
> <item id=1 quantity=3 price=1.10 />
> <item id=2 quantity=6 price=2.20 />
> <item id=3 quantity=9 price=3.30 />
> </items>
>
>
> Thanks.
>
>


Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.