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.


0
theKirk (2)
9/27/2005 10:08:04 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
601 Views

Similar Articles

[PageSpeed] 32

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" <theKirk@discussions.microsoft.com> wrote in message 
news:F5525332-BACC-4606-A925-2570C20B86AA@microsoft.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.
>
> 


0
alexkr (6)
9/28/2005 5:29:16 PM
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" <theKirk@discussions.microsoft.com> wrote in message 
> news:F5525332-BACC-4606-A925-2570C20B86AA@microsoft.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.
> >
> > 
> 
> 
> 
0
theKirk (2)
9/28/2005 5:36:11 PM
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" <theKirk@discussions.microsoft.com> wrote in message 
news:F3FC24D9-7620-419F-A973-E87DFA4128F2@microsoft.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" <theKirk@discussions.microsoft.com> wrote in message
>> news:F5525332-BACC-4606-A925-2570C20B86AA@microsoft.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.
>> >
>> >
>>
>>
>> 


0
alexkr (6)
9/28/2005 5:48:10 PM
Reply:

Similar Artilces:

De-serialization of existing XML
I have an XML in the following format: (sample here) <cars> <car name = "Ford Mustang"> <![CDATA[This is a great car.]]> <Company>Ford</Company> </car> </cars> I have written two c# classes as follows: Class # 1 ------- car.cs [XmlRoot("car")] public class Car { private string _name = ""; private string _company= ""; [XmlAttribute("name")] public string Name { get { return _name ; } set { _name = value; } } [X...

sorting data in columns
How can I sort multiple columns simultaneously? i.e. I have sixteen columns of numerical data that I want to be able to apply the same Sort to each column individually but I do not want to have to highlight each column separately as this will take considerably longer. Save your workbook first! Try sorting one column, then selecting the next and hit the F4 key. It shouldn't take too long if it works ok. Spiderman wrote: > > How can I sort multiple columns simultaneously? i.e. I have sixteen columns > of numerical data that I want to be able to apply the same Sort to each &...

What to do?
Hi Everybody? I have problem when I try to build offline data file from Pivot tabel which is connected to Cube on the Analysis Server. Excel return this message: No columns that microsoft excel can use were returned from this query! What to do? ...

Date conversion question
Am trying to understand why is that when I have a variable MaxDate (undeclared) and is has a value of 38697 and if I use =TEXT(MaxDate,"mm/dd/yy") I get the correct value of 12/12/09 but if I use function =CDATE(MaxDate) I get 12/11/2005 as an output? Also the format command didn't work either to convert MaxDate with the code =format(MaxDate, "mm/dd/yy") as it also gave 12/11/2005 when the correct output was 12/12/09. I am trying to understand this. Thanks, Chet Assuming you are using XL2003 or lower... if you click to Tools/Options = on the menu bar, th...

GPIO read/write on intel using DDK example : Genport
Hi All, I would like to control one of the 14 GPIO provided on the Poulsbo UW15w. and I would like to use the driver (Genport) provided in DDK. Do you know if this would work to set and clear GPIO. How do I get the Address of the Port i want to set. (gpdwrite . ...) is it set in the .inf Thanks regards Norrih On Feb 16, 12:41=A0am, Norrih <Nor...@discussions.microsoft.com> wrote: > Hi All, > > I would like to control one of the 14 GPIO provided on the Poulsbo UW15w. > and I would like to use the driver (Genport) provided in DDK. > > Do you...

Compare Data
Let's say I want to compare data thusly: I have two columns of numbers, G and N. Column G has more numbers than column N, and includes every number in column N. In each cell in column O is a string associated with the number in column N. I want to comare a number in column N with all the numbers in column G and when I find a match, copy the string in column O to the appropriate cell in column M. I want to repeat this process until all the strings in column O have been matched to their numbers in column G. Whew! So. How do I do this? Thanks, Tommy One way: M1: =VLOOKU...

Write access to a LDAP server.
Is there any way to enable write access in Outlook to my LDAP server? The LDAP server allows this functionality, Outlook doesn't. Any plugins that can do this? Thanks. Derek ...

DATA DUMP WARNING #2
Maybe the ultimate lesson in this is backup backup backup. Do backups early and often. and use a large cycle - don't write a backup onto the immediately previous media! -- Regards Bob Peel, Microsoft MVP - Money For UK tips & fixes see http://support.microsoft.com/default.aspx?scid=fh;EN-GB;mny. For wishes or suggestions see http://register.microsoft.com/mswish/suggestion.asp or for UK wishes http://www.microsoft.com/uk/support/money/feedback I do not respond to any emails that I have not specifically asked for. <DrWoodardOnDS@hotmail.com> wrote in message news:11095315...

Re: How can I edit the GAL?
Check - "IMI GAL Modify" - ttp://www.imibo.com/imidev/Exchange/imigm.htm - we use it from few years... "Frusturat$d" <Frusturatd@discussions.microsoft.com> wrote in message news:47579443-D2BA-4B62-AD45-EAB7889154A2@microsoft.com... > Is there a way to give a user (say in HR or Admin) rights to the GAL so > that > they can update employee phone numbers and locations? ...

Win 7/64 pro "Reserved partition" question
My installed W7 has its active booting partition be a small 100 MB partition that has no drive letter assigned, it is called "reserved". I'm told that if I had installed to a formatted drive, this small partition would not exist. I'd like to get rid of it and have W7 boot right to the C: system partition. In doing some fiddling with ShadowProtect Inage Backup I managed to eliminate the small partition and now I boot just fine to C: and my "F8" function on booting still works fine. Am I in a "bad" situation or is this acceptable to keep t...

Should write history for more than one HR change per day
Currently, Human Resources only allows writing a history record for one change per day per employee when the Enable Reason For Change is marked. If an employee changes departments and positions both in the same day, only one of the records will be written. It seems logical that multiple changes could happen for an employee in a day. Why not allow writing more than one history record per day? -- BrianB ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" but...

XML to Database mapping
Hi folks! Has anyone out there come across a code generation tool that will do the following:- - read in a number of handwritten XSD files - create a set of SQL Server tables which can hold the same strctured data as the XSDs - create mapping code that will read individual XML docs compliant with the XSDs and insert the data into the database - create mapping code that will extract data from the database into compliant individual XML documents. My project will use about 200 xml schemas. Some elements will be commonly reused e.g. the Address element. Naturally, I would like these to b...

Can I change the color of a form based on status?
I have a form for work orders. I track the work order number, part number, serial number, etc. I would like to add a combo box with work order status Open/Closed. I know how to do this part. I was wondering if I can link a command that will change the color of either the box or the form based on the current status of the work order. When I scroll through the work order form I rapidly know which work orders are open and closed based on the color. The parts are shipped out to various agencies for repair and sometimes it may be months before we see our parts back. Once a week I go t...

Getting data from Access to Excel?
How would you go about pulling data from Access database into Excel? (Like weekly reports) Troy, Data|Get External Data|New Database Query Select MS Access Database The Wizard should take you through the remaining steps of selecting the data you want to import and the criteria (if any) that you wish to use. PC "Troy" <corptkm@yahoo.com> wrote in message news:nLDXa.3726$Jk5.3138269@feed2.centurytel.net... > How would you go about pulling data from Access database into Excel? (Like > weekly reports) > > You can also push-it-out of Access to Excel by (While...

need help with tables so form okat- multiple equipment for 1 job
Here goes. I know this should be simple not sure why I can't see this right. Here is what I want to end up with not sure the best way to set up the tables to get what I want. and/or best way to create the form(from a query) or using form wizard pulling in tables that I need. I want to END up with a Form for all possible JOBS(cleaning jobs) with equipment needed and soaps needed for each job. There are many pieces of equipment for each job - mop, bucket, etc.(can't figure out how to get this in a form without listing with a comma) Have so far - don't thinks the tables a...

Pivot Table data source
I have created a pivot table in the same workbook as the data source but whenever I try to refresh the data I get a message saying "This command requires at least two rows of source data.............." On checking the data source some cells on only one row are selected. If I change the selection to what it should be everything works fine but the selection reverts back to the same row and cells the next time I open the workbook. How can I make Excel (2007) retain the data source selection? Hi Pete If you have given the correct range, then it should retain the values. Howe...

SQL Question
Can anybody decipher what this is trying to say? DECODE(SUBSTR(DISC_CD,1,3),NULL,' ','367','DNP','408','NIC','607','NIC',DECODE(FLOOR(ASCII(SUBSTR(DISC_CD,1,1))/60),0,'NIC','DNP') Examples of the disc_cd are 36712, 60706, etc.... Thanks, Mo -- Mo ----------------------------------------------------------------------- Moe's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1250 View this thread: http://www.excelforum.com/showthread.php?threadid=31984 Moe <Moe.1g6v7z@excelforum-nospam.com...

Email template insert data fields into subject line.
Hello, Is there a way to insert data fields into the subject line in email templates? I would like to add a case number so our customers can see it in the Subject line. Thanks, Steve ...

Range of data is variable...
I am working on a year-end report for my clients that shows them information associated with their accounts. Most of the information on each client's reports relates to the current year and is easy to retreive from the tables that store all the clients' information. However, there is historical information for each client that is more difficult to report. I want to display a graph for each client showing the year-to-year change in "value" for them. But since each client has a different number of data points, it is proving hard for me to format the graphs properly. ...

data labels disappear
Hello all, I'm using 2003, I have a scatter chart and whenever I check the box to show data labels, then save (to a share point workspace) then close & re-open, the data labels disappear? Thanks for your assistance! Vera ...

Conditional format based on data from another column
Hi Yesterday I asked about the possibility of conditional formatting a range of 20 random numbers into 2 different formats. Thank you for that, but now it seems that 3 of my 20 numbers are now requiring a different cell to be highlighted in yet another colour. Currently the situation is as follows:- Column G has a list of random numbers ranging from 1-20, with columns either side pertaining to the random number located in the relevant cell in Column G. It now appears that 3 numbers in this random list do not require highlighting in Column G and have amended the condition formattin...

Outlook 2007 Edit Business Card Format
I've just started using Outlook 2007 with the Business Contact Manager. I'd like to edit the format of the Business Card in both Outlook and Business Contact Manager. I have discovered how to edit an individual card but not how to edit all the existing cards and future cards. Can this be done and if so how? Thanks, Bob It can't be done; that functionality just isn't built into Outlook. I = expect, though, that some enterprising programmer will produce an = inexpensive tool or sample application to apply a particular format to = all EBCs.=20 --=20 Sue Mosher, Outlook ...

Newbie question regarding GP Invoice drill-down
Is there a way to put an URL pointing to an image of the invoice in the invoice/payable data entry screen so that we can click on it later to view the image? Thanks Bill Bill, You can attach a document (image in this case) to Transaction Entry window by clicking on the icon that looks like a sheet of paper next to the Voucher number. Clicking on the paper clip icon in the notes window opens an OLE Container into which you can insert the image and save it. Frank Hamelly MCP-GP, MCT, MVP East Coast Dynamics www.eastcoast-dynamics.com blog: www.gp2themax.blogspot.com Bill, For more ...

Rename Data file
I am using outlook 2003 and I have to data file for two email accounts, the problem is the two file have the same name( presonal folders). I want to rename them. Was there some reason for not simply creating subfolders for each email account and using rules to file appropriately? "hazzaa" <anonymous@discussions.microsoft.com> wrote in message news:206da01c45933$9a83a760$a501280a@phx.gbl... > I am using outlook 2003 and I have to data file for two > email accounts, the problem is the two file have the same > name( presonal folders). > > I want to rename them....

Reading in XML file, changing elements and saving back to the file
Hi Reading in XML file, changing elements and saving back to the file, how can i do that, I want to be able to read an XML file and read out Elements. for example <name>Tom</tom> When I read from a file i want to save the XML document in memory of the computer and when i am finished flush it back to the file, that means i want to be able to access the element in memory of the computer and when i change it will write it back with new changes. What is the Best way to do that ? I have tried it wiht xmlReader and xmlWrite, this is not saved in the computer. Gerald Maher wrote: &...