62,266
社区成员
发帖
与我相关
我的任务
分享
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
* { margin: 0; padding: 0; }
#outer_div { position: relative; width: 250px; margin: 50px 40px; border-top: solid 3px Red; }
#inner_div { position: absolute; top:10px; left: 20px; background: #AAA; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="outer_div">
The outer div
<div id="inner_div">
This is some text...
</div>
</div>
</form>
</body>
</html>

//ShowPic.ashx
C# code
<%@ WebHandler Language="C#" Class="ShowPic" %>
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
public class ShowPic : IHttpHandler {
public void ProcessRequest (HttpContext context) {
int empID = System.Convert.ToInt32(context.Request.QueryString["EmployeeID"]);
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["NorthwindConnectionString1"].ConnectionString;
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select Photo from Employees where EmployeeID=@empID";
cmd.Parameters.AddWithValue("@empID", empID);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (reader.HasRows)
{
if (reader.Read())
{
context.Response.ContentType = "Image/bmp";
//下面这些代码在一般的读取二进制时没必要. 可以参考其他代码.
const int OleHeaderLength = 78;
int length = ((Byte[])reader["Photo"]).Length;
int strippedImageLength = length - OleHeaderLength;
byte[] strippedImageData = new byte[strippedImageLength];
Array.Copy((Byte[])reader["Photo"], OleHeaderLength,
strippedImageData, 0, strippedImageLength);
context.Response.BinaryWrite(strippedImageData);
context.Response.BinaryWrite((Byte[])reader["Photo"]);
}
}
}
}
public bool IsReusable {
get {
return false;
}
}
}<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="EmployeeID" DataSourceID="SqlDataSource1"
EmptyDataText="没有可显示的数据记录。">
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" ReadOnly="True"
SortExpression="EmployeeID" />
<asp:TemplateField HeaderText="Last Name">
<ItemTemplate>
<asp:LinkButton runat="server" ID="LinkButton1" Text='<%# Eval("LastName") %>' OnClientClick="return false;" />
<cc1:PopupControlExtender ID="pce" runat="server" TargetControlID="LinkButton1" PopupControlID="pnlPic" Position="Bottom">
</cc1:PopupControlExtender>
<asp:Panel runat="server" ID="pnlPic">
<img alt='<%# Eval("LastName") %>' src= 'ShowPic.ashx?EmployeeID=<%# Eval("EmployeeID") %>' />
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:NorthwindConnectionString1.ProviderName %>"
SelectCommand="SELECT [EmployeeID], [LastName] FROM [Employees]">
</asp:SqlDataSource>