i have a string from xml below like :
string str= @"
";
i want bind it to datagrid
please help me how to it do ?
thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jan 3, 2012, 5:07 AM
Try following code,
string str = @"http://www.w3.org/2001/XMLSchema-instance""
divid1
divid2
";
xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
StringReader theReader = new StringReader(str);
DataSet theDataSet = new DataSet();
theDataSet.ReadXml(theReader);
Gridview1.DataSource = theDataSet;
Hope this help.
Jignesh TrivediPosted Jan 3, 2012, 5:06 AM
Try following code,
string str = @"http://www.w3.org/2001/XMLSchema-instance""
divid1
divid2
";
xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
StringReader theReader = new StringReader(str);
DataSet theDataSet = new DataSet();
theDataSet.ReadXml(theReader);
Gridview1.DataSource = theDataSet;
Hope this help.
Nipun TomarPosted Jan 2, 2012, 5:52 AM
Try this Article Link:
http://www.extremeexperts.com/Net/Articles/BindingXMLtoDataGrid.aspx
Thanks
Gohil JayendrasinhPosted Jan 2, 2012, 5:45 AM
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xmldatasource.aspx
Vahid BakhtiaryPosted Jan 2, 2012, 5:26 AM
i try it and the code was right
but in my project i can't use of DataSet
now i how to it do
please help me
thanks
Satyapriya NayakPosted Jan 1, 2012, 10:48 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
// string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
//SqlConnection con = new SqlConnection(connStr);
//con.Open();
DataSet reportData = new DataSet();
reportData.ReadXml(Server.MapPath("test.xml"));
GridView1.DataSource = reportData;
GridView1.DataBind();
//con.Close();
}
}
test.xml
Thanks
Vahid BakhtiaryPosted Jan 1, 2012, 8:47 AM
i try it and your code is right
but in datagrid display below like :
item
divid1
divid2
but i want display name every columns be name my node for example below like:
ID
divid1
divid2
or if i have a xml below like :
in datagrid dispaly below like:
ID Age
divid1 20
please help me how to define columns with name every node
thanks
Dharmesh SharmaPosted Jan 1, 2012, 8:27 AM
void Country()
{
List
XmlDocument doc = new XmlDocument();
String value = "";
doc.Load("http://where.yahooapis.com/v1/countries?appid=[your yahoo API]");
XmlNodeList NewsList = doc.GetElementsByTagName("places");
foreach (XmlNode node in NewsList)
{
foreach (XmlNode sub_node in node)
{
XmlElement ConnectionElement = (XmlElement)sub_node;
value = ConnectionElement.GetElementsByTagName("name")[0].InnerText;
_obj_country.Add(value);
}
}
datagrid.DataSource = _obj_country;
datagrid.DataBind();
}
This is yahoo api use code in this code get xml from yahoo and you can bind into grid and dropdown
thanks