AddBooksCatagory.aspx.cs
上传用户:tjxpgg
上传日期:2017-05-14
资源大小:2244k
文件大小:2k
源码类别:

SilverLight

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Xml;
  12. public partial class AddBooksCatagory : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         
  17.         if (!IsPostBack)
  18.         {
  19.             
  20.             bind();
  21.         }
  22.     }
  23.     public void bind()
  24.     {
  25.         this.GridView1.DataSource = DBHelp.Select("select * from Categories");
  26.         this.GridView1.DataBind();
  27.     }
  28.    
  29.     
  30.     protected void Button1_Click(object sender, EventArgs e)
  31.     {
  32.         string name = this.TextBox1.Text.Trim();
  33.         if (DBHelp.Update("insert into Categories values('" + name + "')"))
  34.         {
  35.             bind();
  36.         }else
  37.         {
  38.             ClientScript.RegisterStartupScript(this.GetType(), "", "alert('添加失败╭∩╮(︶︿︶)╭∩╮')");
  39.         }
  40.      }
  41.     private XmlDocument xmlTree = new XmlDocument();
  42.     public void jiazaiXml()
  43.     {
  44.         DataTable dt= DBHelp.Select("select top 1 * from Categories asc");
  45.         int id=Convert.ToInt32( dt.Rows[0][0]);
  46.         xmlTree.Load(Server.MapPath("TreeView.xml"));
  47.         XmlElement xe = xmlTree.CreateElement("siteMapNode");
  48.         xe.SetAttribute("title", this.TextBox1.Text);
  49.         xe.SetAttribute("url","BookList.aspx?id="+id.ToString());
  50.         xe.SetAttribute("description", "");
  51.         xmlTree.SelectSingleNode("siteMapNode").AppendChild(xe);
  52.         xmlTree.Save(Server.MapPath("TreeView.xml"));
  53.     }
  54.     protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
  55.     {
  56.         string id = this.GridView1.Rows[e.RowIndex].Cells[0].Text;
  57.         if (DBHelp.Update("delete  from  Categories where id=" + id + ""))
  58.         {
  59.             bind();
  60.         }
  61.         else
  62.         {
  63.             ClientScript.RegisterStartupScript(this.GetType(), "", "alert('删除失败')", true);
  64.         }
  65.     }
  66. }