My XMLFile is as shown below - <?xml version="1.0" encoding="utf-8"?>
-
<root>
-
<BookDetails>
-
<bookid>156</bookid>
-
<bookname>xml</bookname>
-
<author>rajendran</author>
-
</BookDetails>
-
<BookDetails>
-
<bookid>789</bookid>
-
<bookname>ajax</bookname>
-
<author>kumaran</author>
-
</BookDetails>
-
</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
4 1666 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: -
-
<div>
-
Select BookID:
-
<asp:DropDownList ID="drdBooksId" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drdBooksId_SelectedIndexChanged">
-
</asp:DropDownList><br />
-
<br />
-
BookName:
-
<asp:TextBox ID="txtBookName" runat="server"></asp:TextBox><br />
-
<br />
-
Author:
-
<asp:TextBox ID="txtAuthor" runat="server"></asp:TextBox>
-
</div>
-
-
C# Code Behind: -
-
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
if (!IsPostBack)
-
{
-
BindDrdBooksId();
-
}
-
}
-
-
public void BindDrdBooksId()
-
{
-
DataSet xmlDataSet = new DataSet();
-
-
// In ASP.Net use App_Data Directory for xml data files
-
xmlDataSet.ReadXml(Server.MapPath("../App_Data/books.xml"));
-
-
// if xml file is in the same directory
-
// xmlDataSet.ReadXml("books.xml");
-
-
drdBooksId.DataSource = xmlDataSet;
-
drdBooksId.DataValueField = "bookid";
-
drdBooksId.DataTextField = "bookid";
-
drdBooksId.DataBind();
-
-
}
-
-
protected void drdBooksId_SelectedIndexChanged(object sender, EventArgs e)
-
{
-
bindXmlData(drdBooksId.SelectedItem.Value);
-
}
-
-
public void bindXmlData(string bookID)
-
{
-
DataSet xmlDataSet = new DataSet();
-
-
// In ASP.Net use App_Data Directory for xml data files
-
xmlDataSet.ReadXml(Server.MapPath("../App_Data/books.xml"));
-
-
// if xml file is in the same directory
-
//xmlDataSet.ReadXml("books.xml");
-
-
DataRow[] dRow = xmlDataSet.Tables[0].Select("bookid=" + bookID);
-
-
txtBookName.Text = dRow[0]["bookName"].ToString();
-
txtAuthor.Text = dRow[0]["author"].ToString();
-
}
-
-
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 ;-)
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
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.
We're glad to have you here contributing.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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:
|
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
|
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
|
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");
| |
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
|
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" )
|
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.
|
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
|
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
-----------------------------------------------------------------------------------
|
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,...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |