473,372 Members | 1,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Rookie question : Writing edited form data (gridview) to 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.
Nov 12 '05 #1
3 5643
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike P | last post by:
How do you get access to the values you have entered under edit mode in a gridview? I only seem to be able to access the values prior to them being edited. protected void...
2
by: Mike Baugh | last post by:
I am using visual studio 2005 to develop a form using c# I have 3 datagrids on one form. I can set the row color based on a certain value in a column. However this color applies to all 3...
9
by: =?Utf-8?B?UHJhdmlu?= | last post by:
We are using .net Framework 1.1 We are having one page on which we are using this Grid component. From this page we open a popup for adding new record as well as for editing an existing record...
0
by: koonda | last post by:
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my...
0
by: kageyone | last post by:
I am having trouble updating a dataset representation of an xml file. The xml file is read into a dataset which is bound to a gridview control. The edit functionality was added to the code and...
7
by: xx75vulcan | last post by:
Hi, I've got a PHP Upload Form that works great, unless that is, the image your uploading has been modified through a photo editing software. Example: if I upload the image straight from a...
2
by: frankiefrank | last post by:
I have been struggling with this issue for some time, hope someone here can help out. After facing the issue (will describe it soon) in a solution with Ajax and a Master Page I decided to try it...
1
by: dan | last post by:
Hi, I'd like to the row being edited to be also selected. That is, I don't want one row to be selected while another row is being edited. If a user clicks on the 'Edit' button I'd like the...
1
by: nomad | last post by:
Hi, I have an editable GridView. When I select Edit it jumps into the RowEditing event. Within this even I can get the row index of the row being edited, along with the value of the column to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.