在DataList中单击ImageButton,显示图片详细信息

2024-02-07 08:58

本文主要是介绍在DataList中单击ImageButton,显示图片详细信息,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

以下是HTML代码:
<% @ Page Language="C#" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true"
    CodeFile
="ListPhoto.aspx.cs" Inherits="ListPhoto" Title="List Photo" 
%>

< asp:Content  ID ="Content1"  ContentPlaceHolderID ="ContentPlaceHolder1"  runat ="Server" >
    
< asp:DataList  ID ="dlPhoto"  runat ="server"  RepeatColumns ="4"  RepeatDirection ="Horizontal"
        CellPadding
="0"  Width ="790px"  OnItemCommand ="dlPhoto_ItemCommand" >
        
< ItemTemplate >
            
< asp:ImageButton  Width ="185"  ID ="ibtnPhoto"  ImageUrl ='<%#  FormatURL(DataBinder.Eval(Container,"DataItem.user_name"),DataBinder.Eval(Container, "DataItem.photo_type_id"),DataBinder.Eval(Container, "DataItem.photo_id")) % > '
                runat="server" AlternateText="click list Details information!" CommandName="Detail" OnClick="ibtnPhoto_Click" />
< br  />
            
< asp:Label  ID ="lblPhotoType"  runat ="server"  Text ='<%#  DataBinder.Eval(Container, "DataItem.photo_type_id")% > '
                Visible="false">
</ asp:Label >< br  />
            
< asp:Label  ID ="lblPhotoName"  runat ="server"  Text ='<%#  DataBinder.Eval(Container, "DataItem.photo_id")% > '
                Visible="false">
</ asp:Label >
        
</ ItemTemplate >
    
</ asp:DataList >
</ asp:Content >
以下是对应的后台代码:
using  System;
using  System.Data;
using  System.Configuration;
using  System.Collections;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;

public   partial   class  ListPhoto : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if(!Page.IsPostBack)
        
{
            
if(!(Convert.ToBoolean(Session["isLogin"])))
            
{
                Response.Redirect(
"Login.aspx");
            }

            
else
            
{
                System.Data.SqlClient.SqlConnection conn 
= new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DogsManagerConnectionString"].ToString());
                
string code,strSQL;
                code 
= Request.QueryString["code"].ToString();
                
if(code == "A")
                
{
                    strSQL 
= string.Format("select user_name,photo_type_id,photo_id,photo from E_Photo where user_name='{0}'", Session["name"].ToString());
                }

                
else
                
{
                    strSQL 
= string.Format("select user_name,photo_type_id,photo_id,photo from E_Photo where user_name='{0}' AND photo_type_id={1}", Session["name"].ToString(),code);
                }

                System.Data.SqlClient.SqlCommand cmd 
= new System.Data.SqlClient.SqlCommand(strSQL, conn);
                
try
                
{
                    conn.Open();
                    
this.dlPhoto.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    
this.dlPhoto.DataBind();
                }

                
catch(System.Data.SqlClient.SqlException sql)
                
{
                    Response.Write(
"wrong information:<br>" + sql.Message);
                }

                
finally
                
{
                    cmd.Dispose();
                    conn.Close();
                }

            }

        }

    }


    
protected string FormatURL(object userName, object typeID, object photoID)
    
{
        
return string.Format("ReadImage.aspx?userName={0}&typeID={1}&photoID={2}",
            userName.ToString(), typeID.ToString(), photoID.ToString());
    }

    
protected void dlPhoto_ItemCommand(object source, DataListCommandEventArgs e)
    
{
        
if(e.CommandName == "Detail")
        
{
            
string userName = Session["name"].ToString();
            
string typeId = ((Label)e.Item.FindControl("lblPhotoType")).Text;
            
string photoId = ((Label)e.Item.FindControl("lblPhotoName")).Text;
            
string Format = string.Format("ListPhotoDetail.aspx?userName={0}&typeID={1}&photoID={2}",
                userName, typeId, photoId);
            
//ImageButton ibtnDetail = (ImageButton)e.Item.FindControl("ibtnPhoto");
            
//ImageButton ibtnDetail = (ImageButton)this.dlPhoto.Items[e.Item.ItemIndex].FindControl("ibtnPhoto");
            
//添加单击事件
            
//ibtnDetail.Click += new ImageClickEventHandler(ibtnDetail_Click);
            respon(Format);
        }

    }

    
/// <summary>
    
/// 在模板列中添加的单击事件
    
/// </summary>    

    //void ibtnDetail_Click(object sender, ImageClickEventArgs e)
    
//{
    
//    Response.Redirect("http://www.baidu.com");
    
//}
    void respon(string url)
    
{
        Response.Write(
"<script language='javascript'>window.open('"+url+"','newWindow');</script>");
    }

    
protected void ibtnPhoto_Click(object sender, ImageClickEventArgs e)
    
{
        
    }

}

 以下是显示详细页面ListPhotoDetail.aspx对应的HTML代码:

 

<% @ Page Language="C#" AutoEventWireup="true" CodeFile="ListPhotoDetail.aspx.cs" Inherits="ListPhotoDetail1"  %>

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

< html  xmlns ="http://www.w3.org/1999/xhtml"   >
< head  runat ="server" >
    
< title > List Photo Detail </ title >
</ head >
< body >
    
< form  id ="form1"  runat ="server" >
    
< table  border ="0"  cellpadding ="0"  cellspacing ="0" >
        
< tr >
            
< td  colspan ="2"  style ="height: 53px" >
                
< span  style ="font-size: 14pt" >< strong > List Details Photo </ strong ></ span ></ td >
        
</ tr >
        
< tr >
            
< td  colspan ="2" >
                
< asp:Image  ID ="imgPhoto"  runat ="server"   /></ td >
        
</ tr >
        
< tr >
            
< td  align ="right"  style ="height: 24px" >
                
< asp:Label  ID ="lblLoadDate"  runat ="server"  Text ="UpLoad Date:" ></ asp:Label ></ td >
            
< td  align ="left"  style ="height: 24px" >
                
< asp:TextBox  ID ="txtLoadDate"  runat ="server"  Width ="164px" ></ asp:TextBox ></ td >
        
</ tr >
        
< tr >
            
< td  align ="right" >
                
< asp:Label  ID ="Label2"  runat ="server"  Text ="Description:" ></ asp:Label ></ td >
            
< td  align ="left" >
                
< asp:TextBox  ID ="txtDesc"  runat ="server"  Height ="248px"  TextMode ="MultiLine"  Width ="401px" ></ asp:TextBox ></ td >
        
</ tr >
    
</ table >
        
< asp:Button  ID ="btnOK"  runat ="server"  Text ="OK"   />
    
</ form >
</ body >
</ html >

以下是对应的后台代码:

 

using  System;
using  System.Data;
using  System.Configuration;
using  System.Collections;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;

public   partial   class  ListPhotoDetail1 : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
        
if(!Page.IsPostBack)
        
{
            
string username = Request.QueryString["userName"].ToString();
            
string typeid = Request.QueryString["typeID"].ToString();
            
string photoid = Request.QueryString["photoID"].ToString();
            System.Data.SqlClient.SqlConnection conn 
= new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DogsManagerConnectionString"].ToString());
            
string strSQL = string.Format("select Photo_Desc,UpLoad_Date from E_Photo where user_name='{0}' and photo_type_id=" +
                
"{1} and photo_id='{2}'", username, typeid, photoid);
            System.Data.SqlClient.SqlCommand cmd 
= new System.Data.SqlClient.SqlCommand(strSQL, conn);
            
try
            
{
                conn.Open();
                System.Data.SqlClient.SqlDataReader reader 
= cmd.ExecuteReader(CommandBehavior.CloseConnection);
                
if(reader.Read())
                
{
                    
//设置其他项
                    this.txtDesc.Text = reader["Photo_Desc"].ToString();
                    
this.txtLoadDate.Text = reader["UpLoad_Date"].ToString();
                }

            }

            
catch(System.Data.SqlClient.SqlException sql)
            
{
                
throw sql;
            }

            
finally
            
{
                cmd.Dispose();
                conn.Close();
            }

            
//设置图片的显示
            this.imgPhoto.ImageUrl = FormatURL(username, typeid, photoid);
        }

    }

    
/// <summary>
    
/// 获取格式化地址
    
/// </summary>
    
/// <param name="userName">user name</param>
    
/// <param name="typeID">phto type id</param>
    
/// <param name="photoID">photo number</param>
    
/// <returns></returns>

    protected string FormatURL(string userName, string typeID, string photoID)
    
{
        
return string.Format("ReadImage.aspx?userName={0}&typeID={1}&photoID={2}",
            userName, typeID, photoID);
    }

}

这篇关于在DataList中单击ImageButton,显示图片详细信息的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/687194

相关文章

第10章 中断和动态时钟显示

第10章 中断和动态时钟显示 从本章开始,按照书籍的划分,第10章开始就进入保护模式(Protected Mode)部分了,感觉从这里开始难度突然就增加了。 书中介绍了为什么有中断(Interrupt)的设计,中断的几种方式:外部硬件中断、内部中断和软中断。通过中断做了一个会走的时钟和屏幕上输入字符的程序。 我自己理解中断的一些作用: 为了更好的利用处理器的性能。协同快速和慢速设备一起工作

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

安卓链接正常显示,ios#符被转义%23导致链接访问404

原因分析: url中含有特殊字符 中文未编码 都有可能导致URL转换失败,所以需要对url编码处理  如下: guard let allowUrl = webUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {return} 后面发现当url中有#号时,会被误伤转义为%23,导致链接无法访问

C#实战|大乐透选号器[6]:实现实时显示已选择的红蓝球数量

哈喽,你好啊,我是雷工。 关于大乐透选号器在前面已经记录了5篇笔记,这是第6篇; 接下来实现实时显示当前选中红球数量,蓝球数量; 以下为练习笔记。 01 效果演示 当选择和取消选择红球或蓝球时,在对应的位置显示实时已选择的红球、蓝球的数量; 02 标签名称 分别设置Label标签名称为:lblRedCount、lblBlueCount

Android 10.0 mtk平板camera2横屏预览旋转90度横屏拍照图片旋转90度功能实现

1.前言 在10.0的系统rom定制化开发中,在进行一些平板等默认横屏的设备开发的过程中,需要在进入camera2的 时候,默认预览图像也是需要横屏显示的,在上一篇已经实现了横屏预览功能,然后发现横屏预览后,拍照保存的图片 依然是竖屏的,所以说同样需要将图片也保存为横屏图标了,所以就需要看下mtk的camera2的相关横屏保存图片功能, 如何实现实现横屏保存图片功能 如图所示: 2.mtk

Spring MVC 图片上传

引入需要的包 <dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.1</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-

Prompt - 将图片的表格转换成Markdown

Prompt - 将图片的表格转换成Markdown 0. 引言1. 提示词2. 原始版本 0. 引言 最近尝试将图片中的表格转换成Markdown格式,需要不断条件和优化提示词。记录一下调整好的提示词,以后在继续优化迭代。 1. 提示词 英文版本: You are an AI assistant tasked with extracting the content of

lvgl8.3.6 控件垂直布局 label控件在image控件的下方显示

在使用 LVGL 8.3.6 创建一个垂直布局,其中 label 控件位于 image 控件下方,你可以使用 lv_obj_set_flex_flow 来设置布局为垂直,并确保 label 控件在 image 控件后添加。这里是如何步骤性地实现它的一个基本示例: 创建父容器:首先创建一个容器对象,该对象将作为布局的基础。设置容器为垂直布局:使用 lv_obj_set_flex_flow 设置容器

C# dateTimePicker 显示年月日,时分秒

dateTimePicker默认只显示日期,如果需要显示年月日,时分秒,只需要以下两步: 1.dateTimePicker1.Format = DateTimePickerFormat.Time 2.dateTimePicker1.CustomFormat = yyyy-MM-dd HH:mm:ss Tips:  a. dateTimePicker1.ShowUpDown = t

研究人员在RSA大会上演示利用恶意JPEG图片入侵企业内网

安全研究人员Marcus Murray在正在旧金山举行的RSA大会上公布了一种利用恶意JPEG图片入侵企业网络内部Windows服务器的新方法。  攻击流程及漏洞分析 最近,安全专家兼渗透测试员Marcus Murray发现了一种利用恶意JPEG图片来攻击Windows服务器的新方法,利用该方法还可以在目标网络中进行特权提升。几天前,在旧金山举行的RSA大会上,该Marcus现场展示了攻击流程,