您的位置:首页 > 运维架构

使用网页对话框来显示图片 window.open()

2008-06-07 00:51 405 查看
这个主要用到了JS中的 window.open(url,windowname,location)

url 目标窗口的url 如果url 是一个空字符串,浏览器将打开一个空白窗口

windowname window对象名称

location 窗口属性设置可选参数

Default.aspx 页如下

放置一个linkbutton,并写下事件处理

protected void LinkButton1_Click(object sender, EventArgs e)

{

Response.Redirect("<script>window.open('image.aspx','','width600,height=500')</script>");

}

新建一个image.aspx页来显示弹出的那个页面

放置DataList

前台主要

<asp:DataList ID="DataList1" runat="server">

<ItemTemplate>

<table style="width:80px;height:100px" border="1" cellpadding="0" cellspacing="0">

<tr>

<td>

<asp:ImageButton ID="btn_image" runat="server" Height="100px" Width="80px" ImageUrl='<%#DataBinder.Eval(Container.DataItem,"Image") %>' />

</td>

</tr>

</table>

</ItemTemplate>

</asp:DataList>

后台代码:

public partial class image : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

bind(this.DataList1);

}

}

public void bind(DataList dl)

{

PagedDataSource ps = new PagedDataSource();

string sql = "select * from tb_image";

SqlConnection con = new SqlConnection("");

SqlDataAdapter sda = new SqlDataAdapter(sql, con);

DataSet ds = new DataSet();

sda.Fill(ds,"tb_image");

//指定PagedDataSource 的数据源

ps.DataSource = ds.Tables["tb_image"].DefaultView;

ps.AllowPaging = true;

ps.PageSize = 5;

//指定DataList的数据源

dl.DataSource = ps;

dl.DataKeyField = "id";

dl.DataBind();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: