ListBooksByCategory.aspx.cs
资源名称:SunShine.rar [点击查看]
上传用户:tjxpgg
上传日期:2017-05-14
资源大小:2244k
文件大小:2k
源码类别:
SilverLight
开发平台:
ASP/ASPX
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- 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 Microsoft.Practices.EnterpriseLibrary.Common;
- using Microsoft.Practices.EnterpriseLibrary.Data;
- public partial class ListBooksByCategory : System.Web.UI.Page
- {
- Database DB = DatabaseFactory.CreateDatabase();
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- Bind();
- }
- }
- public void Bind()
- {
- 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");
- this.GridView1.DataBind();
- this.DropDownList1.DataSource = DBHelp.Select("select * from Categories");
- this.DropDownList1.DataTextField = "name";
- this.DropDownList1.DataValueField = "id";
- this.DropDownList1.DataBind();
- }
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- e.Row.Attributes.Add("onmouseover", "da=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
- e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=da");
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- int count= this.GridView1.Rows.Count;
- for (int i = 0; i < count; i++)
- {
- if ((this.GridView1.Rows[i].Cells[0].FindControl("CheckBox2") as CheckBox).Checked==true)
- {
- string id= this.GridView1.Rows[i].Cells[4].Text;
- DBHelp.Update("update books set CategoryId=" + this.DropDownList1.SelectedValue + " where id=" + id + "");
- Bind();
- }
- }
- }
- }