473,668 Members | 2,407 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retriving data from xml file

90 New Member
My XMLFile is as shown below
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  <root>
  3. <BookDetails> 
  4.     <bookid>156</bookid>
  5.      <bookname>xml</bookname>
  6.      <author>rajendran</author>
  7. </BookDetails> 
  8. <BookDetails> 
  9.     <bookid>789</bookid> 
  10.     <bookname>ajax</bookname>
  11.      <author>kumaran</author>
  12. </BookDetails>
  13. </root>
Now if I need to retrive all the bookid alone and if i need to display that in a dropdownlist then how should I do in asp.net using C#?
and in the same wise after making the selected index changed in dropdownlist how should I retrive the particular details of bookid and display that in the textbox?

please help me?
I do not have clear cut idea how to proceed.
thanks in advance

regards
raghul
Aug 1 '08 #1
4 1666
coolcode
6 New Member
Hi Raghu I have coded the following ASP.Net C# code for you to bind the xml data file with DropDownList control.

SelectedIndexCh anged event of the DropDownList is used in the C# code to bind the corresponding properties values of selected bookId.

HTML Code:

Expand|Select|Wrap|Line Numbers
  1.  
  2.         <div>
  3.             Select BookID:
  4.             <asp:DropDownList ID="drdBooksId" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drdBooksId_SelectedIndexChanged">
  5.             </asp:DropDownList><br />
  6.             <br />
  7.             BookName:
  8.             <asp:TextBox ID="txtBookName" runat="server"></asp:TextBox><br />
  9.             <br />
  10.             Author:
  11.             <asp:TextBox ID="txtAuthor" runat="server"></asp:TextBox>
  12.         </div>
  13.  
  14.  


C# Code Behind:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. protected void Page_Load(object sender, EventArgs e)
  4.     {
  5.         if (!IsPostBack)
  6.         {
  7.             BindDrdBooksId();
  8.         }
  9.     }
  10.  
  11.     public void BindDrdBooksId()
  12.     {
  13.         DataSet xmlDataSet = new DataSet();
  14.  
  15.         // In ASP.Net use App_Data Directory for xml data files
  16.         xmlDataSet.ReadXml(Server.MapPath("../App_Data/books.xml"));
  17.  
  18.         // if xml file is in the same directory
  19.         // xmlDataSet.ReadXml("books.xml");
  20.  
  21.         drdBooksId.DataSource = xmlDataSet;
  22.         drdBooksId.DataValueField = "bookid";
  23.         drdBooksId.DataTextField = "bookid";
  24.         drdBooksId.DataBind();
  25.  
  26.     }
  27.  
  28.     protected void drdBooksId_SelectedIndexChanged(object sender, EventArgs e)
  29.     {
  30.         bindXmlData(drdBooksId.SelectedItem.Value);
  31.     }
  32.  
  33.     public void bindXmlData(string bookID)
  34.     {
  35.         DataSet xmlDataSet = new DataSet();
  36.  
  37.         // In ASP.Net use App_Data Directory for xml data files
  38.         xmlDataSet.ReadXml(Server.MapPath("../App_Data/books.xml"));
  39.  
  40.         // if xml file is in the same directory
  41.         //xmlDataSet.ReadXml("books.xml");
  42.  
  43.         DataRow[] dRow = xmlDataSet.Tables[0].Select("bookid=" + bookID);
  44.  
  45.         txtBookName.Text = dRow[0]["bookName"].ToString();
  46.         txtAuthor.Text = dRow[0]["author"].ToString();
  47.     }
  48.  
  49.  

I saved the provided xml schema and dummy xml data file in the App_Data. You can try this code, I hope this will help you.

Good Luck ;-)
Aug 2 '08 #2
Curtis Rutland
3,256 Recognized Expert Specialist
coolcode:
In the future, please try to avoid giving other members fully coded solutions. On this forum, we want to promote leaning and understanding. While sometimes the best way to do that is with a code sample, copy-paste code teaches nothing other than how to copy and paste. So perhaps suggest the namespaces and objects to look into, or post a code sample that can't be directly copied and pasted, but please don't do other members assignments/homework for them.

MODERATOR
Aug 2 '08 #3
coolcode
6 New Member
coolcode:
In the future, please try to avoid giving other members fully coded solutions. On this forum, we want to promote leaning and understanding. While sometimes the best way to do that is with a code sample, copy-paste code teaches nothing other than how to copy and paste. So perhaps suggest the namespaces and objects to look into, or post a code sample that can't be directly copied and pasted, but please don't do other members assignments/homework for them.

MODERATOR
Yea sure. Next time I will keep in mind to provide only logic behind the code rather than complete solution. This solution is my first contributing post.
Aug 2 '08 #4
Curtis Rutland
3,256 Recognized Expert Specialist
We're glad to have you here contributing.
Aug 2 '08 #5

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

Similar topics

4
3233
by: Eric Kincl | last post by:
Hello, its been a while since I posted/looked here... my normal email client doesn't handle newsgroups :( (ximian evolution) I was wondering how you stick a file into a database, and then retrive it again for the user with PHP/MySQL. I tried the following which apparently didnt work... Very quick overview of what I did... html
2
5322
by: Niyazi | last post by:
Hi, I have to retrieve a data from AS400 DB2 and after working with data I have to export into one of existing Excel file. I can connect into specific library in AS400 DB2 using AS400 Client-Access v5.2 program using (in VB.NET) ODBC driver (DSN Name …) . I can retrieve datam work on it using VB.NET and I can send into 'NEW' Excel file. My first problem starts here:
2
2460
by: Manish Naik | last post by:
Hi, Using ASP.Net, I want to store and retrive documents (Word, excel, etc) from SQL Server 2000 database. I have tried image type data field, but could not succed. Can any one help me please. Regards, Manish Naik
0
1113
by: dzemo | last post by:
Which is the fastest way to "pump" data into crystal report in vb.net 2003? Is it: 1. content report as set datasource to dataset and filter data on fill dataset 2. set an output file and set connection direct to server and use selection formula to filter data 3. use odbc or something else I'll have a grate amount of data (over 1000000 records in one year) thx
8
3765
by: Alpha | last post by:
I created the following code in my C# program but it's giving me error message at run time of : XML.XPATH.XPATHEXCEPTION : Namespace Manager or XSLTContext needed. This query has a prefix, variable or user defined function. Can someone see what I'm doing wrong? Thanks, Alpha private XPathDocument unityMessages = new XPathDocument("UnityMessages.xml");
2
3084
by: balakrishnan.dinesh | last post by:
Hi frnds, Im having a problem with retriving "\" backslash , In my javascript client side page , ill get the response from the server side , the response will contain some url like "\bank\index.htm" . So what i have to do is, ill get those url and display them in textfields , The problem is , while retriving the url , the backslashes are missing , for some backslashes its generating junk values like box
2
1438
by: chinu124 | last post by:
In my first file i.e File1 i am having a text field having value "FName" now i want to fetch the data of that textfield n i want to send the input data into my mail body. File2.asp <% Dim objNewMail Set objNewMail = CreateObject("CDONTS.NewMail") Dim strName strName = Request( "FName" )
1
2579
by: Kunal Nandi | last post by:
can any one give me the code for uploading and retriving image using Blob, with jsp at front end and oracle8i at the back end ??????? i have tried this using long raw datatype i was able to upload it, but while retriving first i have to create a temporary image file for that. and then i m able to retirve it on the web page, but i want it to be directly retrived on the web page.
2
1654
by: soma.gunasekaran | last post by:
Hi All , I've stored the Image file..... But i want to retriving the Image files from MSACCSS 2003 (JPEG,bmp,Gif and etc....) So Pls help me........ help me............... Thanking you, Somasundaram G
0
1092
by: pchaitanya | last post by:
hi all, suppose in a table if i have columns namely name,entrydate now on retriving and binding to a gridview how can I get names rowwise and entrydate columnwise on a gridview on Xaxis I want entrydate and yaxis names in following format -----------------------------------------------------------------------------------
0
8382
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7405
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1787
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.