DataGrid中的高級ToolTip 2

CS
 1 using  System;
 2 using  System.Collections;
 3 using  System.ComponentModel;
 4 using  System.Data;
 5 using  System.Data.SqlClient;
 6 using  System.Drawing;
 7 using  System.Web;
 8 using  System.Web.SessionState;
 9 using  System.Web.UI;
10 using  System.Web.UI.WebControls;
11 using  System.Web.UI.HtmlControls;
12 using  System.Configuration;
13
14 namespace  CSDNTech
15 {
16    /// <summary>
17    /// DataGrid中的高級ToolTip 的摘要說明。
18    /// </summary>

19    public class DataGrid中的高級ToolTip : System.Web.UI.Page
20    {
21        protected System.Web.UI.WebControls.DataGrid DataGrid1;
22        protected string Conn = ConfigurationSettings.AppSettings["DBConn"];
23        private DataTable dt;
24
25        private void Page_Load(object sender, System.EventArgs e)
26        {
27            // 在此處放置用戶代碼以初始化頁面
28            this.Format_DataGrid();
29        }

30
31        private void Format_DataGrid()
32        {
33            SqlConnection cn = new SqlConnection(Conn);
34            cn.Open();
35            try
36            {
37                SqlCommand com = new SqlCommand("select Top 16 CustomerID, CompanyName, ContactTitle,Country, City, Address,PostalCode,Phone,Fax from Customers",cn);
38                SqlDataAdapter adp = new SqlDataAdapter(com);
39                dt = new DataTable();
40                adp.Fill(dt);
41                this.DataGrid1.DataSource = dt;
42                this.DataGrid1.DataBind();
43            }

44            finally
45            {
46                cn.Close();
47            }

48        }

49
50        Web 窗體設計器生成的代碼
71
72        private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
73        {
74            if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
75            {
76                e.Item.Attributes.Add("onmouseover""this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#C8F7FF';");
77                e.Item.Attributes.Add("onmousemove""Show('"+dt.Rows[e.Item.ItemIndex]["country"].ToString()+"','" 
78                    +dt.Rows[e.Item.ItemIndex]["City"].ToString()+"','" 
79                    +dt.Rows[e.Item.ItemIndex]["Address"].ToString()+"','" 
80                    +dt.Rows[e.Item.ItemIndex]["PostalCode"].ToString()+"','" 
81                    +dt.Rows[e.Item.ItemIndex]["Phone"].ToString()+"','" 
82                    +dt.Rows[e.Item.ItemIndex]["Fax"].ToString()+"');"); 
83                e.Item.Attributes.Add("onmouseout"
84                    "this.style.backgroundColor=this.oldcolor;Hide();"); 
85            }

86        }

87    }

88}
相關文章
相關標籤/搜索