Net8:xml read-write operation "XML file instance of AD control"

Source: Internet
Author: User

The original Published time: 2008-08-05--from my Baidu article [imported by moving tools]

"With the DataList control, the DataList control learns, mostly knowing that other buttons CommandName properties should be changed to Edit,update,delete"

Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;

Using System.Xml;
Using System.Xml.XPath;

public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Fill ();
}

}

protected void Fill ()
{
DataSet ds=new DataSet ();
Ds. READXML (Server.MapPath ("~/app_data/ad.xml"));
Datalist1.datasource=ds. Tables[0]. DefaultView;
Datalist1.databind ();

session["DST"]=DS;
}

protected void Button1_Click (object sender, EventArgs e)
{

}
protected void Datalist1_selectedindexchanged (object sender, EventArgs e)
{

}
protected void Datalist1_editcommand (object source, DataListCommandEventArgs e)
{
Datalist1.edititemindex = E.item.itemindex;
Fill ();
}
protected void Datalist1_updatecommand (object source, DataListCommandEventArgs e)
{
DataSet ds = (DataSet) session["DST"];
Ds. Tables[0]. rows[e.item.itemindex]["IMAGEURL"] = ((TextBox) E.item.findcontrol ("TextBox2")). Text.tostring ();
Ds. Tables[0]. rows[e.item.itemindex]["NAVIGATEURL"] = ((TextBox) E.item.findcontrol ("TextBox5")). Text.tostring ();
Ds. Tables[0]. rows[e.item.itemindex]["AlternateText"] = ((TextBox) E.item.findcontrol ("TextBox1")). Text.tostring ();
Ds. Tables[0]. rows[e.item.itemindex]["Keyword"] = ((TextBox) E.item.findcontrol ("TextBox3")). Text.tostring ();
Ds. Tables[0]. rows[e.item.itemindex]["Impressions"] = ((TextBox) E.item.findcontrol ("TextBox4")). Text.tostring ();

session["DST"] = ds;
Ds. WRITEXML (Server.MapPath ("~/app_data/ad.xml"));

        Datalist1.edititemindex=-1;
        Fill ();
   }
    protected void Datalist1_cancelcommand (object source, DataListCommandEventArgs e)
     {
        datalist1.edititemindex =-1;
        Fill ();
   }
    protected void Datalist1_deletecommand (object source, DataListCommandEventArgs e)
     {
        DataSet ds = (DataSet) session["DST"];
        ds. Tables[0]. Rows.remove (ds. Tables[0]. Rows[e.item.itemindex]);
        session["DST"] = ds;
        ds. WRITEXML (Server.MapPath ("~/app_data/ad.xml"));

Fill ();
}
protected void Button5_click (object sender, EventArgs e)
{
DataSet ds = (DataSet) session["DST"];
DataRow dr = ds. Tables[0]. NewRow ();

dr["ImageUrl"] = URL. Text.tostring ();
dr["NAVIGATEURL"] = ng. Text.tostring ();
dr["AlternateText"] = na. Text.tostring ();
dr["Keyword"] = kw. Text.tostring ();
dr["Impressions"] = QZ. Text.tostring ();

Ds. Tables[0]. Rows.Add (DR);
session["DST"] = ds;

Ds. WRITEXML (Server.MapPath ("~/app_data/ad.xml"));
Fill ();
DIV1. Visible = false;
Panel1.visible = false;
}
protected void Button7_click (object sender, EventArgs e)
{
Panel1.visible = true;
Na. Focus ();
}
protected void LinkButton1_Click (object sender, EventArgs e)
{
DIV1. Visible = true;
Ng. Focus ();
}
protected void Button6_click (object sender, EventArgs e)
{
String name = Fu. Filename.tostring ();
int size = Convert.ToInt32 (fu. Postedfile.contentlength);
String type1 = Fu. PostedFile.ContentType.ToString ();
String type = Type1. Substring (0, 5);

        if (type = = "image")
        {
            Fu. Postedfile.saveas (Server.MapPath ("~/img/") + name);
            img. IMAGEURL = Server.MapPath ("~/img/") + name;
            URL. Text = Server.MapPath ("~/img/") + name;
       }
        Else
        {
             URL. Text = "not allowed type";
       }
   }
    protected void Button8_click (object sender, EventArgs e)
    {
         Response.Redirect ("default2.aspx");
   }
}

----------------------------------------------

Content of Ad.xml:

<?xml version= "1.0" standalone= "yes"?>
<Advertisements>
<Ad>
<ImageUrl>~/img/logo.gif</ImageUrl>
<NavigateUrl>http://www.hc115.com</NavigateUrl>
<AlternateText> Hongcheon Pharmaceutical </AlternateText>
<Keyword> Hospital Evaluation </Keyword>
<Impressions>50</Impressions>
</Ad>
<Ad>
<ImageUrl>http://www.baidu.com/img/baidu_logo_rw_0808_hzl.gif</ImageUrl>
<NavigateUrl>http://www.baidu.com</NavigateUrl>
<AlternateText> Baidu </AlternateText>
<Keyword> Baidu </Keyword>
<Impressions>60</Impressions>
</Ad>
<Ad>
<ImageUrl>F:\wuwenjie\net8\img\iask.gif</ImageUrl>
<NavigateUrl>http://www.iask.com</NavigateUrl>
<AlternateText> Love Q </AlternateText>
<Keyword> Love Search </Keyword>
<Impressions>30</Impressions>
</Ad>
</Advertisements>

Net8:xml read-write operation "XML file instance of AD control"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.