惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - Angelo Dell'inferno

[ASP.NET] 基于.Net Remoting 的网站访问监控模块 [转]Run a Http Response Filter together with an Ajax Update Panel [ASP.NET] (转)地址栏参数的判断 [ASP.NET] 实现Label自动换行 [ASP.NET] 验证码生成 [ASP.NET] 实现客户端浏览服务端目录的页面 [ASP.NET]Treeview 控件显示服务端目录文件夹及文件 [C#] GridView导出到Excel [C#] 获取两个时间点的时间间隔 [SQL Server][转]数据库并发控制——活锁&死锁 [JavaScript] 防止页面被嵌入Iframe [SQL Server] 存储过程事务 [SQL Server] T-SQL 连接数据库方法 [C#] 杀Excel进程 [ASP.NET] (原创)自定义GridView分页 [C#] 将DataSet内容导入到Excel (矩阵区域导出) [ASP.NET] 服务器端下载文件实现 [Oracle] 日期相关操作 [ORACLE] 函数大全
[ASP.NET] HyperLink + Image 实现动态图片链接
Angelo Dell'inferno · 2008-06-02 · via 博客园 - Angelo Dell'inferno

要在GridView中动态绑定附件,如果附件存在且为图片时,显示该图片,并且建立超链接;如果附件不是图片,则只显示附件名称,建立超链接;

Html 代码:
<
span>

<asp:HyperLink ID="lnkAttachment" runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem,"AttachmentPath") %>'

                             Target="_blank" Font-Underline="True">

<asp:Image ID="imgAttachment" runat="server"/>

</asp:HyperLink>

</

span>后台代码:

 1 /// <summary>
 2    /// 设置图片的可见性
 3    /// 无附件时,不显示图片
 4    /// </summary>
 5    /// <param name="sender"></param>
 6    /// <param name="e"></param>

 7    protected void gvReplyList_RowDataBound(object sender, GridViewRowEventArgs e)
 8    {
 9        if (e.Row.RowType == DataControlRowType.DataRow)
10        {
11            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
12            {
13                HyperLink lnkReplyAttach = e.Row.FindControl("lnkReplyAttach"as HyperLink;
14                Image imgReplyAttach = e.Row.FindControl("imgReplyAttach"as Image;
15                string extension = lnkReplyAttach.NavigateUrl.Substring(lnkReplyAttach.NavigateUrl.LastIndexOf('.'+ 1).ToLower();
16                //无附件时,不显示超链接
17                if (lnkReplyAttach.NavigateUrl.Trim() == "")
18                {
19                    lnkReplyAttach.Visible = false;
20                    imgReplyAttach.Visible = false;
21                }

22                //存在附件但是不是图片时,只显示附近的名称
23                else if (extension != "jpg" && extension != "gif")
24                {
25                    lnkReplyAttach.Text = lnkReplyAttach.NavigateUrl.Substring(lnkReplyAttach.NavigateUrl.LastIndexOf('/'+ 1);
26                    imgReplyAttach.Visible = false;
27                }

28                //附件为图片时,显示图片,不显示该附件文件名称
29                else
30                {
31                    //图片URL
32                    imgReplyAttach.ImageUrl = lnkReplyAttach.NavigateUrl;
33                    //自适应图片尺寸
34                    imgReplyAttach.Attributes.Add("onload""if(this.width>340||this.width<=0){this.resized=true;this.width=340;}");
35                }

36                //删除按钮
37                ImageButton imgDelete = e.Row.FindControl("imgReplyDelete"as ImageButton;
38                //删除确认对话框
39                imgDelete.Attributes.Add("onclick""return confirm('" + PublicConstString.confirm_Delete_Relpy + "')");
40            }

41        }

42    }