CS
 1 None.gif using  System;
 2 None.gif using  System.Collections;
 3 None.gif using  System.ComponentModel;
 4 None.gif using  System.Data;
 5 None.gif using  System.Data.SqlClient;
 6 None.gif using  System.Drawing;
 7 None.gif using  System.Web;
 8 None.gif using  System.Web.SessionState;
 9 None.gif using  System.Web.UI;
10 None.gif using  System.Web.UI.WebControls;
11 None.gif using  System.Web.UI.HtmlControls;
12 None.gif using  System.Configuration;
13 None.gif
14 None.gif namespace  CSDNTech
15 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
16ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
17InBlock.gif    /// DataGrid中的高级ToolTip 的摘要说明。
18ExpandedSubBlockEnd.gif    /// </summary>

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

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

44InBlock.gif            finally
45ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
46InBlock.gif                cn.Close();
47ExpandedSubBlockEnd.gif            }

48ExpandedSubBlockEnd.gif        }

49InBlock.gif
50ContractedSubBlock.gifExpandedSubBlockStart.gif        Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
51InBlock.gif        override protected void OnInit(EventArgs e)
52ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
53InBlock.gif            //
54InBlock.gif            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
55InBlock.gif            //
56InBlock.gif            InitializeComponent();
57InBlock.gif            base.OnInit(e);
58ExpandedSubBlockEnd.gif        }

59InBlock.gif        
60ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
61InBlock.gif        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
62InBlock.gif        /// 此方法的内容。
63ExpandedSubBlockEnd.gif        /// </summary>

64InBlock.gif        private void InitializeComponent()
65ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{    
66InBlock.gif            this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
67InBlock.gif            this.Load += new System.EventHandler(this.Page_Load);
68InBlock.gif
69ExpandedSubBlockEnd.gif        }

70ExpandedSubBlockEnd.gif        #endregion

71InBlock.gif
72InBlock.gif        private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
73ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
74InBlock.gif            if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
75ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
76InBlock.gif                e.Item.Attributes.Add("onmouseover""this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#C8F7FF';");
77InBlock.gif                e.Item.Attributes.Add("onmousemove""Show('"+dt.Rows[e.Item.ItemIndex]["country"].ToString()+"','" 
78InBlock.gif                    +dt.Rows[e.Item.ItemIndex]["City"].ToString()+"','" 
79InBlock.gif                    +dt.Rows[e.Item.ItemIndex]["Address"].ToString()+"','" 
80InBlock.gif                    +dt.Rows[e.Item.ItemIndex]["PostalCode"].ToString()+"','" 
81InBlock.gif                    +dt.Rows[e.Item.ItemIndex]["Phone"].ToString()+"','" 
82InBlock.gif                    +dt.Rows[e.Item.ItemIndex]["Fax"].ToString()+"');"); 
83InBlock.gif                e.Item.Attributes.Add("onmouseout"
84InBlock.gif                    "this.style.backgroundColor=this.oldcolor;Hide();"); 
85ExpandedSubBlockEnd.gif            }

86ExpandedSubBlockEnd.gif        }

87ExpandedSubBlockEnd.gif    }

88ExpandedBlockEnd.gif}