För det första så vill jag tacka all som hjälpt mig med mitt förra xml datalist problem:)
Nu har jag ett nytt problem:) Det är hur det ska skrivas ut i min lista, nu skriver det ut allt som står i min xml fil inte så snyggt och med mellan slag mellan varje element i xml filen, hur gör jag nu min listbox snygg? Bifogar här nedan min kod
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.XPath;
namespace listaxml
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.ListBox ListBoxContacts;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!(Page.IsPostBack))
{
//Response.Write(Server.MapPath(""));
myFunction();
}
}
protected void myFunction()
{
// fylla din listbox
XmlTextReader reader = new XmlTextReader(Server.MapPath("webs.xml"));
while (reader.Read())
{
// Adda varje namn till din listbox
if ((reader.NodeType == XmlNodeType.Element) && (reader.Name=="Email"))
reader.Read();
//ListBoxContacts.Items.Add(reader.Value + "\<br\>");
//Response.Write(reader.Value + "\<br\>");
}
}
\#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// \<summary\>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// \</summary\>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
\#endregion
}
}
Så här ser min xml fil ut
<?xml version="1.0" standalone="yes"?>
<Webs>
<Web>
<Responsible />
<Name>Kurt</Name>
<LastName>Nilsson</LastName>
<Email>kurt.nilsson@ibm.se</Email>
<Company>IBM</Company>
<Contact>Kund</Contact>
</Web>
<Web>
<Responsible />
<Name>Kurt</Name>
<LastName>Johansson</LastName>
<Email>kurt@ibm.se</Email>
<Company>IBM</Company>
<Contact>Kund</Contact>
</Web>
</webs>
hur gör jag om jag bara vill ha ut Name och LastName i min listbox?