473,406 Members | 2,208 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,406 software developers and data experts.

XML with C# or ASP: XML Confused!!!!

I am VERY New To XML and I am having a heap of trouble writing an application that will allow for the creation, modification and final output in a specific format via C# and asp .net.

I am sure I will ask several questions before I'm done but here is my first:

Basically I have a WEB application that I would like to be used to create an XML file (because of the structure of an XML file) to organize a cost estimator segregated by different cost sections. Most of the Sections will be exactly the same so if I can get one page to work I think can pretty much copy, paste and modifiy after that.

I have the code to generate the file and the initial tags. I can add tags to it from different pages no problem.

The Problem, begins when I come to a section where there may be a dynamic number of cost records and their corresponding descriptions segregated within a specific section.

I want to be able to add individual costs via a data grid, then once added, display them within the same datagrid. But how can I initially bind to data that doen't exist? I can create the tags with the attributes I need as well as the inner text like so:
[HTML]
<Section2>
<text>Main text area that each section will have. even with no cost tags</text>
<cost value="100.00>this is a cost description</cost>
<cost value=45.89">this is another cost description</cost>
etc......
</Section2>
[/HTML]
How can I display the value attribute of each cost tag and the inner text within a datagrid within each section as I create them.

Here is the code I use to create the main text tag:
Expand|Select|Wrap|Line Numbers
  1. XmlTextReader reader = new XmlTextReader(fileName);
  2. XmlDocument doc = new XmlDocument(); 
  3. doc.Load(reader);
  4. reader.Close();
  5. XmlElement root = doc.DocumentElement;
  6. XmlElement s1 = doc.CreateElement("Section2");             
  7. s1.InnerXml =  "<text>" + this.TextBox1.Text + "</text>".Trim() ;
  8. root.AppendChild(s1);
  9. doc.Save(fileName);                
  10. bindGrid() //--the function that binds the data to the grid
  11.  
this is the code I use to add values to the xml file within the footer of a datagrid that I set up to add records via the ItemCommand event.
Expand|Select|Wrap|Line Numbers
  1. XmlDocument doc = new XmlDocument();
  2. doc.Load(fileName);
  3. XmlNode s2 = doc.SelectSingleNode("/Root/Section2");
  4. XmlElement cost = null;
  5. XmlAttribute valattrib = null;
  6. //Create New cost XML Element 
  7. cost = doc.CreateElement("cost");
  8. //New Attribute 
  9. valattrib = doc.CreateAttribute("value");
  10. // Value given for the new attribute
  11. TextBox tbCostAdd = new TextBox();
  12. tbCostAdd = (TextBox)e.Item.FindControl("tbCostAdd");
  13. valattrib.Value = tbCostAdd.Text;
  14. //Attach the attribute to the XML element
  15. cost.SetAttributeNode(valattrib);
  16. //Value given for the cost element
  17. TextBox tbDescrAdd = new TextBox();
  18. tbDescrAdd = (TextBox)e.Item.FindControl("tbDescrAdd");
  19. cost.InnerText = tbDescrAdd.Text;
  20. s2.AppendChild(cost);
  21. doc.Save(fileName);
  22. bindGrid();
  23.  
  24. //my bind function
  25. private void  bindGrid()
  26. {    
  27.   DataSet ds = new DataSet();           
  28.   ds.ReadXml(fileName); //--read the xml file--//             
  29.   DataGrid1.DataSource = ds;            
  30.   DataGrid1.DataBind();    
  31. }
  32.  
The code adds the new tags with the attributes and text just fine. How can I display them within the datagrid as I add them?

I have looked all over the place for code example but none I found quite answer my question. Maybe I need to change how I creating the cost tag, but I need to associate a description with each cost so I set an attribute as the cost value and the inner text as the description.

Any helpful hints or advice would be greatly apprciated!
Jul 16 '07 #1
1 1541
Dököll
2,364 Expert 2GB
Sorry you did not get a response...

Perhaps it is more .NET related!

Updated your title also for added hits:-)
Dec 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Ohaya | last post by:
Hi, I'm trying to understand a situation where ASP seems to be "blocking" of "queuing" requests. This is on a Win2K Advanced Server, with IIS5. I've seen some posts (e.g.,...
4
by: ASP.Confused | last post by:
I would like to be able to get the type of object that a session variable contains (for example, determine whether it is a string, integer, single precision floating point, ADODB.Recordset, etc...)...
2
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP...
2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added...
0
by: ASP.Confused | last post by:
The old message looked a little stale, so I am re-posting it here. Anybody have any ideas of what I could do?!? The previous responses to this question are below. If you want to look at the...
19
by: Jon Davis | last post by:
I'm reposting this because I really need some advice. I have a web app that makes many queries to the database on every page. In order to save development effort, I've consolidated all database...
2
by: ASP.Confused | last post by:
How would I go about detecting a memory leak? My web hosting provider has our site set up to only have a root "bin" folder for .NET apps, and I would like to be able to watch how much memory is...
5
by: ASP.Confused | last post by:
As you can tell from my previous posts on this issue...I'm really confused :-/ I have a few ASP.NET web applications on my web host's "https" server. Our web host has a single "bin" folder for...
3
by: Goran Djuranovic | last post by:
Hi everyone, I have an ASP.NET application with NT authentication turned on. The default page is an .HTM page with the frameset in it. Frameset contains 3 frames (top, left, main), and each of...
3
by: Alex Maghen | last post by:
Hi. I am really confused about the NTFS permissions that I must set for my ASP.NET 2.0 IIS application to work properly. I have looked at KB:815153 and that helps a *little* bit, but I need...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.