http://www.cppdev.cn/show.aspx?id=33&cid=6
2006-12-19 17:03
811 查看
1.html代码
<HTML>
<HEAD>
<title>DataGridTooltip</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<style type="text/css">
.transparent {
}{ BORDER-RIGHT: indianred 1px solid; BORDER-TOP: indianred 1px solid; DISPLAY: none; FILTER: alpha(opacity=85); BORDER-LEFT: indianred 1px solid; BORDER-BOTTOM: indianred 1px solid; POSITION: absolute; BACKGROUND-COLOR: infobackground } </style>
<script language="javascript">
function Show(Country, City, Address, PostalCode, Phone, Fax)
{
//debugger;
document.getElementById("td1").innerText="国家:"+Country;
document.getElementById("td2").innerText="城市:"+City;
document.getElementById("td3").innerText="地址:"+Address;
document.getElementById("td4").innerText="邮编:"+PostalCode;
document.getElementById("td5").innerText="电话:"+Phone;
document.getElementById("td6").innerText="传真:"+Fax;
x = event.clientX + document.body.scrollLeft;
y = event.clientY + document.body.scrollTop + 20;
Popup.style.display="block";
Popup.style.left = x;
Popup.style.top = y;
}
function Hide()
{
Popup.style.display="none";
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<div id="Popup" class="transparent">
<table border="0" cellpadding="0" bgColor="#00ccff">
<tr>
<td align="center" bgcolor="indianred"><font color="white">联系方式</font></td>
</tr>
<tr>
<td id="td1"></td>
</tr>
<tr>
<td id="td2"></td>
</tr>
<tr>
<td id="td3"></td>
</tr>
<tr>
<td id="td4"></td>
</tr>
<tr>
<td id="td5"></td>
</tr>
<tr>
<td id="td6"></td>
</tr>
</table>
</div>
<asp:DataGrid id="DataGrid1" runat="server">
<FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
<ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
<PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML>
2.cs代码
public class DataGridTooltip : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private DataTable dt;
Page_Load#region Page_Load
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = "data source=meng;initial catalog=Northwind;password=sa;persist security info=True;user id=sa;packet size=4096";
string sqlstr = "select Top 16 CustomerID, CompanyName,ContactTitle,Country, City, Address,PostalCode,Phone,Fax from Customers";
cnn.Open();
SqlDataAdapter ad = new SqlDataAdapter(sqlstr,cnn);
dt = new DataTable();
ad.Fill(dt);
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
}
}
#endregion
DataGrid1_ItemDataBound#region DataGrid1_ItemDataBound
private void DataGrid1_ItemDataBound(object sender,System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.AlternatingItem|| e.Item.ItemType == ListItemType.Item)
{
e.Item.Attributes.Add("onmouseover","this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#C8F7FF';");
e.Item.Attributes.Add("onmousemove",
"Show('"+dt.Rows[e.Item.ItemIndex]["country"].ToString()+"','"
+dt.Rows[e.Item.ItemIndex]["City"].ToString()+"','"
+dt.Rows[e.Item.ItemIndex]["Address"].ToString()+"','"
+dt.Rows[e.Item.ItemIndex]["PostalCode"].ToString()+"','"
+dt.Rows[e.Item.ItemIndex]["Phone"].ToString()+"','"
+dt.Rows[e.Item.ItemIndex]["Fax"].ToString()+"');");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor;Hide();");
}
}
#endregion
Web Form Designer generated code#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
相关文章推荐
- 踏入社会(http://www.sysinfo.cn/index.php?action=show&id=90)
- 做了个非常简单的Flash验证码(附源代码) 转载于http://www.cordyblog.cn/?action=show&amp;id=68
- http://www.fa.omron.com.cn/support/faqview.jsp?pid=0&id=3351&cid=null
- 因ARP欺骗网站源文件被注入了代码http://www.cnbruce.com/blog/showlog.asp?cat_id=32&log_id=1191
- 基于MapServer的WebGIS开发--http://www.gisforum.net/show.aspx?id=1491&cid=27
- ASP.NET 缓存(七)--根据参数缓存页的版本http://www.opent.cn/?action=show&id=194
- MFC 弹出窗口MessageBox的使用[转自http://www.bigasp.com.cn/blog/?action=show&id=51]
- 转:小结一下团队协作中的开源应用 转自:http://www.lingang.gd.cn/?action=show&id=329
- 解决ASP(图像)上传漏洞的方法http://www.cnbruce.com/blog/showlog.asp?cat_id=26&log_id=942
- ASP.NET 缓存(五)--使用文件依赖项缓存页输出http://www.opent.cn/?action=show&id=192
- http://www.microsoft.com/downloads/details.aspx?displaylang=zh-cn&FamilyID=83c3a1ec-ed72-4a79-8961-25635db0192b visal studio 200
- ASP.NET 缓存(四)--使用缓存键依赖项缓存页输出http://www.opent.cn/?action=show&id=191
- 网络蜘蛛原理~ 转 http://www.sysinfo.cn/show.php?id=35
- http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2500&cid=1122
- 明基成人礼:巅峰战将营 http://www.cnvn.com.cn/Article/ShowArticle.asp?ArticleID=3172
- 不完全HTML在线编辑器收集 http://www.cnbruce.com/blog/showlog.asp?log_id=1021
- VS .NET 2005中水晶报表的使用 http://www.tianyablog.com/blogger/post_show.asp?BlogID=116800&PostID=9731765
- 用户自定义ID Generator的例子(http://www.hibernate.org.cn/viewtopic.php?t=6281&highlight=IdentifierGenerator)
- http://www.dev-club.com/club/bbs/showEssence.asp?id=26362
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1004&ojid=1&cid=6866&hide=1&problem=Pro