Lightbox和Datalist

aspx


0 1 < td >
0 2     0 3      OnItemDataBound="DataList1_ItemDataBound" RepeatColumns="3" Width="80%" OnItemCommand="DataList1_ItemCommand">
0 4         < ItemTemplate >
0 5             < table class ="ImageTable" >
0 6                 < tr >
0 7                     < td colspan ="2" class ="ImageTd" >
0 8                         < asp:HyperLink ID ="hlImage" runat ="server" rel ="lightbox[mando]" title='<%# Eval("TagName") % >' ImageUrl=' < %# "imgHandler.ashx?No ="+Eval("No") % >' NavigateUrl=' < %# "imgHandlerO.ashx?No ="+Eval("No") % >'> asp:HyperLink>
09                         <div id="divDesc" runat="server"><%# Eval("Description")%>div>
10                     td>
11                 tr>
12                 <tr>
13                     <td class="ImageTd">
14                         <asp:HyperLink ID="hlModify" runat="server" Text="修 改" NavigateUrl='<%# "~/gallery/albumModify.aspx?No=" + Eval("No") %>'>asp:HyperLink>
15                     td>
16                     <td class="ImageTd">
17                         <asp:LinkButton id="lbtnDelete" runat="server" Text="刪 除" CommandName="Delete" CommandArgument='<%# Eval("No") %>' OnClientClick="return Check();">asp:LinkButton>
18                     td>
19                 tr>
20             table>
21         ItemTemplate>
22     asp:DataList>
23     <script type="text/javascript">
24         window.addEvent('domready',function(){
25             Lightbox.init({descriptions: '.lightboxDesc', showControls: true});
26         });
27     script>
28 td>

圖檔顯示的部分在第8行!透過imgHandler.ashx來顯示


Lightbox的文字述序在第9行,但,還有針對Lighbox的設定要透過程式端來處理!(Lightbox相關請自已參閱)


 


aspx.cs


1      protected void DataList1_ItemDataBound( object sender, DataListItemEventArgs e)
2      {
3         if (e.Item.ItemType == ListItemType.Footer || e.Item.ItemType == ListItemType.Header || e.Item.ItemType == ListItemType.Pager) return;
4
5         ((System.Web.UI.HtmlControls.HtmlGenericControl)(e.Item.FindControl("divDesc"))).Attributes.Add("class", "lightboxDesc " + ((HyperLink)e.Item.FindControl("hlImage")).ClientID.ToString());
6     }

 


 

imgHandler.ashx 設定顯示的圖檔依等比例縮放

00 1 <%@ WebHandler Language= "C#" Class= "imgHandler" %>
00 2
00 3 <%@ WebHandler Language= "C#" Class= "imgHandler" %>
00 4
00 5 using System;
006 using System.Data;
007 using System.Configuration;
008 using System.Collections;
009 using System.Web;
010 using System.Web.Security;
011 using System.Web.UI;
012 using System.Web.UI.WebControls;
013 using System.Web.UI.WebControls.WebParts;
014 using System.Web.UI.HtmlControls;
015 using System.IO;
016 using System.Data.SqlClient;
017 using System.Drawing;

0 18
0 19 public class imgHandler : IHttpHandler
0 20 {
021
022     public void ProcessRequest(HttpContext context)
023     {
024         //指定圖片輸出格式
025         context.Response.ContentType = "image/jpeg";
026
027         讀取資料庫
052
053         //宣告一個 Byte 做資料處理用途
054         byte[] bytes = null;
055
056         try
057         {
058             if (ds.Tables[0].Rows.Count > 0)
059             {
060
061                 bytes = (byte[])ds.Tables[0].Rows[0][1];
062
063                 設定顯示的圖檔依等比例縮放
091             }

092
093         }

094         catch (Exception ex)
095         {
096             throw ex;
097         }

098
099     }

100
101     public bool IsReusable
102     {
103         get
104         {
105             return false;
106         }

107     }

108
109 }

110
111

 

imgHandlerO.ashx 設定顯示的圖檔原始大小

0 1 <%@ WebHandler Language= "C#" Class= "imgHandler" %>
0 2
0 3 <%@ WebHandler Language= "C#" Class= "imgHandler" %>
0 4
0 5 using System;
06 using System.Data;
07 using System.Configuration;
08 using System.Collections;
09 using System.Web;
10 using System.Web.Security;
11 using System.Web.UI;
12 using System.Web.UI.WebControls;
13 using System.Web.UI.WebControls.WebParts;
14 using System.Web.UI.HtmlControls;
15 using System.IO;
16 using System.Data.SqlClient;
17 using System.Drawing;

18
19 public class imgHandler : IHttpHandler
20 {
21
22     public void ProcessRequest(HttpContext context)
23     {
24         //指定圖片輸出格式
25         context.Response.ContentType = "image/jpeg";
26
27         讀取資料庫
52
53         //宣告一個 Byte 做資料處理用途
54         byte[] bytes = null;
55
56         try
57         {
58             if (ds.Tables[0].Rows.Count > 0)
59             {
60
61                 bytes = (byte[])ds.Tables[0].Rows[0][1];
62
63                 設定顯示的圖檔原始大小
78             }

79
80
81         }

82         catch (Exception ex)
83         {
84             throw ex;
85         }

86
87     }

88
89     public bool IsReusable
90     {
91         get
92         {
93             return false;
94         }

95     }

96
97 }

98
99


本文转自
http://www.dotblogs.com.tw/jero/archive/2008/03/21/1988.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值