- 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;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- gvDatabind();
- }
- }
- private DataTable CreateDataSourse()
- {
- System.Data.DataTable dt = new DataTable();
- System.Data.DataRow dr;
- dt.Columns.Add(new System.Data.DataColumn("id", typeof(Int32)));
- dt.Columns.Add(new System.Data.DataColumn("name", typeof(string)));
- dt.Columns.Add(new System.Data.DataColumn("age", typeof(Int32)));
- dt.Columns.Add(new System.Data.DataColumn("sex", typeof(string)));
- dr = dt.NewRow();
- dr[0] = 1;
- dr[1] = "范中磊";
- dr[2] = 26;
- dr[3] = "男";
- dt.Rows.Add(dr);
- dr = dt.NewRow();
- dr[0] = 2;
- dr[1] = "董雪南";
- dr[2] = 25;
- dr[3] = "女";
- dt.Rows.Add(dr);
- dr = dt.NewRow();
- dr[0] = 3;
- dr[1] = "杨弋";
- dr[2] = 24;
- dr[3] = "男";
- dt.Rows.Add(dr);
- dr = dt.NewRow();
- dr[0] = 4;
- dr[1] = "李景荣";
- dr[2] = 55;
- dr[3] = "女";
- dt.Rows.Add(dr);
- return dt;
- }
- private void gvDatabind()
- {
- DataTable dt = CreateDataSourse();
- GridView1.DataSource = dt;
- GridView1.DataBind();
- }
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- e.Row.Attributes.Add("onMouseOver", "this.style.backgroundColor='#e9e9e9'; this.style.cursor='hand';");
- e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor='#f7f7f7';");
- //弹出窗口
- e.Row.Attributes.Add("onclick", "window.open('Default.aspx','','Toolbar=no')");
- }
- }
- }
GridView 实现 鼠标经过感知及点击行弹出窗口
最新推荐文章于 2016-12-31 14:39:00 发布