xml结构<?xml version="1.0" standalone="yes"?>
<content>
  <gallery Name="测试" Folder="92012aed-9092-4154-9b11-b08886b9944a">
    <image Thumb="thum_IMG_4518.jpg" Large="IMG_4518.jpg" Caption="牛老师的工笔画作品" Colour="3a3f36">
      <copy>牛老师的工笔画作品</copy>
    </image>
   
  </gallery>
</content>
 string xmlPath = "~/gghdch/content.xml";
    public string typeID
    {
        get { if (ViewState["typeID"] != null) { return (string)ViewState["typeID"]; } return null; }
        set { if (ViewState["typeID"] != null) { ViewState["typeID"] = value; } else { ViewState.Add("typeID", value); } }
    }
    public string Folder
    {
        get { if (ViewState["Folder"] != null) { return (string)ViewState["Folder"]; } return null; }
        set { if (ViewState["Folder"] != null) { ViewState["Folder"] = value; } else { ViewState.Add("Folder", value); } }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["sysID"] != null)
        {
            if (!IsPostBack)
            {
                typeID = Request.QueryString["typeID"];                Folder = Request.QueryString["Folder"];
                Bind();            }
        }
        else
        {
            Response.Redirect("syslogin.aspx");
        }
    }
    private void ResetParameter()
    {
        GridView1.EditIndex = -1;
        Bind();
    }    private void Bind()
    {
        DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath(xmlPath));
        if (ds.Tables.Count > 0)
        {            DataTable dt = new DataTable();
            dt = ds.Tables[1];
            for (int i = dt.Rows.Count - 1; i >= 0; i--)
            {
                string s = dt.Rows[i]["gallery_Id"].ToString();
                if (dt.Rows[i]["gallery_Id"].ToString() != typeID)
                {
                    dt.Rows.RemoveAt(i);
                }
            }
            this.GridView1.DataSource = dt;
            this.GridView1.DataBind();
            this.GridView1.UpdateAfterCallBack = true;        }
    }    //编辑事件
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        Bind();
        GridViewRow row = GridView1.Rows[e.NewEditIndex];
        for (int i = 3; i < row.Cells.Count - 1; i++)
        {
            TextBox tb = (TextBox)row.Cells[i].Controls[0];
            tb.Width = 50;
        }    }
    //更新事件
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {        GridViewRow row = GridView1.Rows[e.RowIndex]; //获得当前行 
        int numCell = row.Cells.Count;  //共几列单元格(包含Edit和Delete 2列) 
        int currentRow = row.DataItemIndex; //对应DataSet对应的行索引 
        DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath(xmlPath));
        DataTable dt = new DataTable();
        dt = ds.Tables[1];
        for (int i = dt.Rows.Count - 1; i >= 0; i--)
        {
            string s = dt.Rows[i]["gallery_Id"].ToString();
            if (dt.Rows[i]["gallery_Id"].ToString() != typeID)
            {
                dt.Rows.RemoveAt(i);
            }
        }
        DataRow dr;        dr = ds.Tables[1].Rows[row.DataItemIndex];  //找到对应与DataSet行 
        string[] str = null;  //此数组定义表的列名 
        str = new string[] { "copy", "Thumb", "Large", "Caption", "Colour" };
        int j = 0;
        for (int i = 3; i < numCell - 1; i++)
        {
            string cText = ((TextBox)row.Cells[i].Controls[0]).Text;
            string s = str[j];
            dr[str[j]] = cText;            j++;
        }        ds.WriteXml(Server.MapPath(xmlPath));  //将修改写入Table.xml 
        ResetParameter();
    }
    //取消
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        ResetParameter();
    }
    //删除
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        GridViewRow row = GridView1.Rows[e.RowIndex];
        int curr = row.RowIndex;
        DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath(xmlPath));
        DataTable dt = new DataTable();
        dt = ds.Tables[1];
        for (int i = dt.Rows.Count - 1; i >= 0; i--)
        {
            string s = dt.Rows[i]["gallery_Id"].ToString();
            if (dt.Rows[i]["gallery_Id"].ToString() != typeID)
            {
                dt.Rows.RemoveAt(i);
            }
        }
        DataRow dr = ds.Tables[1].Rows[curr];
        dr.Delete();
        ds.WriteXml(Server.MapPath(xmlPath));
        ResetParameter();
    }    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        Bind();
    }
    //添加类别内容
    protected void btnOK_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath(xmlPath));
        DataTable dt = ds.Tables[1];
        DataRow dr = dt.NewRow();
        string fileExt = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
        if (fileExt == ".jpg" || fileExt == ".jpeg" || fileExt == ".png" || fileExt == ".gif")
        {
            string OriPath = Server.MapPath("~/gghdch/" + Folder + "/" + FileUpload1.FileName);
            FileUpload1.PostedFile.SaveAs(OriPath);
            string thumName = Server.MapPath("~/gghdch/" + Folder + "/" + "thum_" + FileUpload1.FileName);
            thumbnail.MakeThumbnail(OriPath, thumName, 50, 50, "HW");
        }
        else
        {
            Anthem.Manager.AddScriptForClientSideEval("alert('上传文件不是图片请重新上传')");
            return;
        }
        dr["copy"] = txtCopy.Text;
        dr["Thumb"] = "thum_" + FileUpload1.FileName;
        dr["Large"] = FileUpload1.FileName;
        dr["Caption"] = txtCaption.Text;
        dr["Colour"] = "3a3f36";
        dr["gallery_Id"] = typeID;
        dt.Rows.Add(dr);
        ds.WriteXml(Server.MapPath(xmlPath));
        Anthem.Manager.AddScriptForClientSideEval("alert('上传成功')");
        Bind();
    }
我想编辑image标签里面的属性   可以更新了之后还是原来的值   有人能帮忙解答下吗

解决方案 »

  1.   

    跟踪调试过吗?是不是向datatable传递过程中丢失的?
      

  2.   

    楼主,调试一样看看问题出在哪里。看看DATATABLE中有值吗?
      

  3.   

    那个问题解决了  现在有一个新的问题  当我删除的时候会删除很多行[code=C#]
    GridViewRow row = GridView1.Rows[e.RowIndex];
            int curr = row.RowIndex;
            DataSet ds = new DataSet();
            ds.ReadXml(Server.MapPath(xmlPath));
            dr = ds.Tables[1].Rows[row.DataItemIndex];
            DataRow dr = ds.Tables[1].Rows[curr]; 
            dr.Delete();
            ds.WriteXml(Server.MapPath(xmlPath));
            ResetParameter();
    [code]
       
      

  4.   

    DataRow 内容是否正确
    遍历XML删除节点
    XmlNodeList xnl=xmlDoc.SelectSingleNode("").ChildNodes;
    foreach(XmlNode xn in xnl)
    {
        XmlElement xe=(XmlElement)xn;
     
    }
    xmlDoc.Save("a.xml");