ListBooksByCategory.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 Microsoft.Practices.EnterpriseLibrary.Common;
  12. using Microsoft.Practices.EnterpriseLibrary.Data;
  13. public partial class ListBooksByCategory : System.Web.UI.Page
  14. {
  15.     Database DB = DatabaseFactory.CreateDatabase();
  16.     protected void Page_Load(object sender, EventArgs e)
  17.     {
  18.         if (!IsPostBack)
  19.         {
  20.            
  21.             Bind();
  22.         }
  23.     }
  24.     public  void Bind()
  25.     {
  26.         this.GridView1.DataSource = DBHelp.Select("select top 10 books.id,Categories.id,title,author,name from books inner join Categories on books.Categoryid=Categories.id");
  27.         this.GridView1.DataBind();
  28.         this.DropDownList1.DataSource = DBHelp.Select("select * from Categories");
  29.         this.DropDownList1.DataTextField = "name";
  30.         this.DropDownList1.DataValueField = "id";
  31.         this.DropDownList1.DataBind();
  32.         
  33.     }
  34.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  35.     {
  36.         
  37.         if (e.Row.RowType == DataControlRowType.DataRow)
  38.         {
  39.             e.Row.Attributes.Add("onmouseover", "da=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
  40.             e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=da");
  41.         }
  42.     }
  43.     protected void Button1_Click(object sender, EventArgs e)
  44.     {
  45.            int count= this.GridView1.Rows.Count;
  46.            for (int i = 0; i < count; i++)
  47.            {
  48.                if ((this.GridView1.Rows[i].Cells[0].FindControl("CheckBox2") as CheckBox).Checked==true)
  49.                {
  50.                   string id= this.GridView1.Rows[i].Cells[4].Text;
  51.                   DBHelp.Update("update books set CategoryId=" + this.DropDownList1.SelectedValue + " where id=" + id + "");
  52.                   Bind();
  53.                }
  54.            }
  55.     }
  56. }