473,509 Members | 3,032 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 1659
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.

SelectedIndexChanged 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
3223
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...
2
5272
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...
2
2457
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. ...
0
1099
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...
8
3755
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,...
2
3065
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...
2
1428
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...
1
2567
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...
2
1651
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,...
0
1078
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...
0
7344
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,...
1
7069
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
7505
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...
1
5060
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...
0
4730
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...
0
3216
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...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
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 ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.