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

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
Intezer
C
Cyber Attacks, Cyber Crime and Cyber Security
The Register - Security
The Register - Security
量子位
Security Latest
Security Latest
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
MyScale Blog
MyScale Blog
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
Jina AI
Jina AI
博客园 - 【当耐特】
P
Palo Alto Networks Blog
Last Week in AI
Last Week in AI
SecWiki News
SecWiki News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
G
GRAHAM CLULEY
宝玉的分享
宝玉的分享
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
有赞技术团队
有赞技术团队
T
Tor Project blog
H
Hacker News: Front Page
A
Arctic Wolf
NISL@THU
NISL@THU
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
V
V2EX
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
I
InfoQ
D
Docker
L
LINUX DO - 最新话题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
U
Unit 42

博客园 - 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    }