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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dharmesh SharmaRank #1,974 · 741 reputationPosted Jan 1, 2012, 3:27 AM EST
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
Vahid Bakhtiary132 reputationPosted Jan 1, 2012, 3:47 AM EST
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 :
Satyapriya NayakRank #47 · 31.5K reputationPosted Jan 1, 2012, 5:48 AM EST
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 Bakhtiary132 reputationPosted Jan 2, 2012, 12:26 AM EST
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
Gohil JayendrasinhRank #490 · 5K reputationPosted Jan 2, 2012, 12:45 AM EST
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xmldatasource.aspx
Nipun TomarRank #90 · 23K reputationPosted Jan 2, 2012, 12:52 AM EST
Try this Article Link:
http://www.extremeexperts.com/Net/Articles/BindingXMLtoDataGrid.aspx
Thanks
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 3, 2012, 12:06 AM EST
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 TrivediRank #16 · 50.3K reputationPosted Jan 3, 2012, 12:07 AM EST
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.