all groups > dotnet xml > september 2005 >
You're in the

dotnet xml

group:

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



Rookie question : Writing edited form data (gridview) to XML theKirk
9/27/2005 3:08:04 PM
dotnet xml: 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.

Re: Rookie question : Writing edited form data (gridview) to XML Alex Krawarik [MSFT]
9/28/2005 10:29:16 AM
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

[quoted text, click to view]

Re: Rookie question : Writing edited form data (gridview) to XML theKirk
9/28/2005 10:36:11 AM
Yep that sounds like the way to do it!!!

Thanks!

[quoted text, click to view]
Re: Rookie question : Writing edited form data (gridview) to XML Alex Krawarik [MSFT]
9/28/2005 10:48:10 AM
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.


[quoted text, click to view]

AddThis Social Bookmark Button