This is my code behind page...when i load xml content to label in asp.net page only table[0][0] index is loaded i want to load whole xml content in to my asp page...like paragraph format....my idea to implent scrollin news in my webpage.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Data;
public partial class NewsEventsUsingXML : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Bind xml data to datalist
BindDatalist();
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
XmlDocument XmlTxt = new XmlDocument();
XmlTxt.Load(Server.MapPath("XMLFile2.xml"));
XmlElement ParentElement = XmlTxt.CreateElement("News1");
XmlElement News = XmlTxt.CreateElement("News");
News.InnerText = txtNews.Text;
ParentElement.AppendChild(News);
XmlTxt.DocumentElement.AppendChild(ParentElement);
XmlTxt.Save(Server.MapPath("XMLFile2.xml"));
}
private void BindDatalist()
{
XmlTextReader XmlReader1 = new XmlTextReader(Server.MapPath("XMLFile2.xml"));
DataSet Xmlds1 = new DataSet();
Xmlds1.ReadXml(XmlReader1);
XmlReader1.Close();
lblNews.Text = Xmlds1.Tables[0].Rows[0][0].ToString();
lblNews.Text=Xmlds1.Tables[0].Rows[1][0].ToString();
lblNews.Text = Xmlds1.Tables[0].Rows[6][0].ToString();
lblNews.DataBind();
//GridView1.DataSource = Xmlds1;
//GridView1.DataBind();
}
}
Loading


Iftikar HussainRank #423 · 5.9K reputationPosted Jun 30, 2013, 10:10 PM EDT
Can you provide the xml data?
Regards,
Iftikar
mohammed shamsheerRank #4,152 · 361 reputationPosted Jun 30, 2013, 10:13 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jun 30, 2013, 10:19 PM EDT
Iftikar
mohammed shamsheerRank #4,152 · 361 reputationPosted Jun 30, 2013, 10:21 PM EDT
Posted Jun 30, 2013, 10:32 PM EDT
You're not iterating the data and directly access data like Xmlds1.Tables[0].Rows[0][0].ToString() and over writing the lblNews.Text value.
foreach (DataRow dr in Xmlds1.Tables[0].Rows)
{
lblNews.Text += dr[0].ToString();
}
Please try this and i've not tested this.
Iftikar HussainRank #423 · 5.9K reputationPosted Jun 30, 2013, 10:45 PM EDT
Regards,
Iftikar
mohammed shamsheerRank #4,152 · 361 reputationPosted Jul 1, 2013, 12:41 AM EDT
Posted Jul 1, 2013, 12:49 AM EDT
mohammed shamsheerRank #4,152 · 361 reputationPosted Jul 1, 2013, 12:53 AM EDT
Posted Jul 1, 2013, 1:11 AM EDT
Posted Jul 1, 2013, 1:11 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 1, 2013, 1:17 AM EDT
Regards,
Iftikar