文件名称:GirdView11
文件大小:478B
文件格式:BAT
更新时间:2011-12-25 08:25:12
GirdView
protected void Page_Load(object sender, EventArgs e) 2 { 3 string keyword=Request["keyword"]; 4 SqlConnection con = db.createConnection(); 5 con.Open(); 6 DataSet ds = new DataSet(); 7 SqlDataAdapter sdr = new SqlDataAdapter(); 8 sdr.SelectCommand = new SqlCommand("select * from ipaddress where ip like'%" + keyword + "%'", con); 9 sdr.Fill(ds); 10 GridView1.DataSource = ds; 11 ds.Dispose(); 12 con.Close(); 13 GridView1.DataBind(); 14 15 } 16 17//给行增加颜色 18 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) 19 { 20 if (e.Row.RowType == DataControlRowType.DataRow) 21 { 22 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#3399FF';"); 23 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;"); 24 } 25 } 26 27 28//GridView有一个PageIndexChanging事件 29 protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 30 { 31 this.GridView1.PageIndex = e.NewPageIndex; 32 this.GridView1.DataBind(); 33 } 34