Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
here is my code i read a XML doc and get all their values in dataset, how to take that all dataset values in gridview. i need the output like the same dataset visualizer.




C#
XmlDocument doc = new XmlDocument();
            doc.Load(PATH);
            
            DataSet ds = new DataSet();
            ds.ReadXml(PATH);
Posted
Updated 28-May-13 19:38pm
v4
Comments
Mac12334 29-May-13 1:35am    
You want to show the dataset value in ASP.NET Gridview ???? or you want to read the dataset value??

Set the datasource of GridView to dataset.
C#
GridView1.DataSource = ds;
GridView1.DataBind();

Refer the links for similar example:
Bind Gridview with XML String using DataSet[^]
How to bind an XML file to a GridView[^]
Bind XML to Grid view in asp.net[^]
ASP.NET: How to use an XMLDataSource with a GridView[^]


--Amit
 
Share this answer
 
C#
GridView1.DataSource =ds.Tables[0];
GridView1.DataBind();
 
Share this answer
 
Hi Change to datatable and u read like this

C#
foreach (DataRow row2 in ds.Rows) {
	string a = null;
	a = row("fieldname").ToString();
}
 
Share this answer
 
v2
Comments
kesav prakash 29-May-13 1:19am    
what i need to give in that fieldname. its a table name or someother else
kesav prakash 29-May-13 1:23am    
a = row("fieldname").ToString();
also canu tell me what is the row here.
Aravindba 29-May-13 23:23pm    
just use break point and see what are the fields in ds ,in ds it show row and column ,and take header of the column as field.

a = row("field").ToString();

just see link posted by Amit .second link "How to bind an XML file to a GridView" in that first image show one table,same like u get in ds,the header of the coloum is id,name and phone is field,use that field .

foreach (DataRow aaa in ds.Rows) {
string a = null;
a = aaa("fieldname").ToString();
}

if ds have multipls row it retrive from ds by using aaa.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900