vs2005中怎么把图片分成多列多行,并且还能实现分页功能
http://www.lvyou114.com/menpiao/Class.asp?ClassID=33效果如这个网站的图片效果,但是要做成动态页面
就是管理员可以通过后台添加图片信息,小弟没有思路
请大大们帮我一把,请详细点说明,谢谢 --------------------编程问答-------------------- 实现方法很多嘛,接拼HTML或者用DATALIST什么的都行啊.
--------------------编程问答-------------------- gridview里加表格了。 --------------------编程问答-------------------- 用datalist 控件 --------------------编程问答-------------------- 用GRIDVIEW,添加模板列,在模板列,你要怎么弄就怎么弄. --------------------编程问答-------------------- GRIDVIEW模板加表格和列后,每一行的图片都一样,不能显示不一样的图片,,如果不用GRIDVIEW,我又不知道怎么实现动态分页,忘各位说明白些 --------------------编程问答-------------------- 发表于:2008-01-12 16:46:074楼 得分:0
用GRIDVIEW,添加模板列,在模板列,你要怎么弄就怎么弄.
这样每行ID一样,怎么取不同ID以显示不同图片呢
--------------------编程问答-------------------- 用GridView不太好弄,用Repeater最简单,下面我随便写的一个,不用担心几行几列的问题,、
因为一行内div满了3个以后会自动换行。你可以自己再调整一下css样式。
<div style="width:500px;">
<asp:Repeater ID="repeater1" runat="server" >
<ItemTemplate>
<div style="float:left; border :1px solid black; margin:2px;padding:6px;width:120px;height:80px;">
在这里放你的图片<br />和说明,需要绑定数据源
</div>
</ItemTemplate></asp:Repeater>
</div>
--------------------编程问答-------------------- 这问题解决了吗?!
--------------------编程问答-------------------- 不好意思,星期天放假去耍了,bwangel 的方法能够动态绑定吗?具体怎么弄啊,谢谢 --------------------编程问答-------------------- 一些过于细节过于基础的问题,还是自己回去慢慢看书慢慢研究吧。
毕竟不是我在作项目,只能给你出出主意。 --------------------编程问答-------------------- 恩,好谢谢 --------------------编程问答-------------------- 前台
<%@ Page Language="C#" MasterPageFile="~/display/Default.master" AutoEventWireup="true"
CodeFile="display.aspx.cs" Inherits="display_display" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" runat="Server">
<asp:DataList ID="DataList1" runat="server" Height="220px" RepeatColumns="3" RepeatDirection="Horizontal"
Width="600px">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%#FormatURL(Eval("Pic_ID")) %>' CommandName="Detail"
CommandArgument='<%# ((System.Data.DataRowView)Container.DataItem)["Pic_ID"] %>' OnClick="ImageButton1_Click" Height="120px" ToolTip="点击查看原图" Width="135px"
/>
<a href='..\display\Photo.aspx?Pic_ID=<%# DataBinder.Eval(Container,"DataItem.Pic_ID") %>' target="_blank"></a>
<br />
<a href='..\display\Photo.aspx?Pic_ID=<%# DataBinder.Eval(Container,"DataItem.Pic_ID") %>' target="_blank">
<span title='<%#DataBinder.Eval(Container, "DataItem.Pic_Title") %>'>
<%# SubStr(Convert.ToString(DataBinder.Eval(Container, "DataItem.Pic_Title")), 8)%>
</a></SPAN>
</ItemTemplate>
</asp:DataList><br />
<br />
<asp:LinkButton ID="FirstLB" runat="server" CommandName="first" OnCommand="LinkButton_Click">第一页</asp:LinkButton>
<asp:LinkButton ID="PreviousLB" runat="server" CommandName="prev" OnCommand="LinkButton_Click">上一页</asp:LinkButton>
<asp:LinkButton ID="NextLB" runat="server" CommandName="next" OnCommand="LinkButton_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="EndLB" runat="server" CommandName="end" OnCommand="LinkButton_Click">最后一页</asp:LinkButton>
总<asp:Label ID="TotalLbl" runat="server"></asp:Label>页 当前第<asp:Label ID="CurrentLbl"
runat="server"></asp:Label>页
<asp:LinkButton ID="JumpLB" runat="server" CommandName="jump" OnCommand="LinkButton_Click">跳到</asp:LinkButton>第
<asp:TextBox ID="TextBox1" runat="server" Width="90px"></asp:TextBox>
页<br />
<br />
</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;
using System.Data.OleDb;
using System.IO;
using System.Drawing;
public partial class display_display : System.Web.UI.Page
{
int CurrentPage;//当前页数
int PageSize; //每页条数
int PageCount; //总页数
int RecordCount;//总条数
public string SubStr(string sString, int nLeng)
{
if (sString.Length <= nLeng)
{
return sString;
}
string sNewStr = sString.Substring(0, nLeng);
sNewStr = sNewStr + "...";
return sNewStr;
}
protected string FormatURL(object strArgument)
{
return "image.aspx?id=" + strArgument.ToString();
}
private void Page_Load(object sender, System.EventArgs e)
{
string pic = Request["Pic_ID"];
PageSize = 9;//每页10条记录
if (!Page.IsPostBack)
{
CurrentPage = 0;//当前页习惯设为0
ViewState["PageIndex"] = 0;//页索引也设为0
//计算总共有多少记录
RecordCount = CalculateRecord();
//计算总共有多少页
if (RecordCount % PageSize == 0)
{
PageCount = RecordCount / PageSize;
}
else
{
PageCount = RecordCount / PageSize + 1;
}
this.TotalLbl.Text = PageCount.ToString();//显示总页数
ViewState["PageCount"] = PageCount;//会话session 对整个 application 有效 ,而视图状态 viewstate相当于某个页面的 session
this.DataListBind();//不可以放在初始化条件之前就绑定,那样的话,如果仅有一页的数据,“下一页”页仍然显示
}
}
//计算总共有多少条记录
private int CalculateRecord()
{
try
{
int recordCount;
OleDbConnection oc = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Server.MapPath(@"~\App_Data\DataBase.aspx")); //数据库使用Northwind;
oc.Open();
string OleDb = "select count(*) as [count] from Picture";
OleDbCommand cmd = new OleDbCommand(OleDb, oc);
OleDbDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
recordCount = Int32.Parse(sdr["count"].ToString());
}
else
{
recordCount = 0;
}
sdr.Close();
oc.Close();
return recordCount;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
//将数据绑定到Datalist控件
public void DataListBind()
{
try
{
int StartIndex = CurrentPage * PageSize;//设定导入的起终地址
string OleDb = "SELECT [Pic_ID], [Pic],[Pic_Title] FROM [Picture] order by [Pic_id] desc";
DataSet ds = new DataSet();
OleDbConnection oc = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Server.MapPath(@"~\App_Data\DataBase.aspx"));
oc.Open();
OleDbDataAdapter sda = new OleDbDataAdapter(OleDb, oc);
sda.Fill(ds, StartIndex, PageSize, "Picture");//这是sda.Fill方法的第一次重载,里面的变量分别是数据集DataSet ,开始记录数StartRecord,最大的记录数MaxRecord,数据表名TableName
this.DataList1.DataSource = ds.Tables["Picture"].DefaultView;
this.DataList1.DataBind();
this.PreviousLB.Enabled = true;
this.NextLB.Enabled = true;
if (CurrentPage == (PageCount - 1)) this.NextLB.Enabled = false;//当为最后一页时,下一页链接按钮不可用
if (CurrentPage == 0) this.PreviousLB.Enabled = false;//当为第一页时,上一页按钮不可用
this.CurrentLbl.Text = (CurrentPage + 1).ToString();//当前页数
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
public void LinkButton_Click(Object sender, CommandEventArgs e)//自己编写的按钮点击事件
{
CurrentPage = (int)ViewState["PageIndex"];//获得当前页索引
PageCount = (int)ViewState["PageCount"];//获得总页数
string cmd = e.CommandName;
//判断cmd,以判定翻页方向
switch (cmd)
{
case "prev"://上一页
if (CurrentPage > 0) CurrentPage--;
break;
case "next":
if (CurrentPage < (PageCount - 1)) CurrentPage++;//下一页
break;
case "first"://第一页
CurrentPage = 0;
break;
case "end"://最后一页
CurrentPage = PageCount - 1;
break;
case "jump"://跳转到第几页
if (this.TextBox1.Text.Trim() == "" || Int32.Parse(this.TextBox1.Text.Trim()) > PageCount)//如果输入数字为空或超出范围则返回
{
return;
}
else
{
CurrentPage = Int32.Parse(this.TextBox1.Text.ToString()) - 1;
break;
}
}
ViewState["PageIndex"] = CurrentPage;//获得当前页
this.DataListBind();//重新将DataList绑定到数据库
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
ImageButton ibt = (ImageButton)sender;
this.Response.Redirect(@"~\display\pic.aspx?Pic_ID=" + ibt.CommandArgument);
// Response.Redirect(@"~\photo.aspx?pic_id =" + ImageButton1.CommandArgument.ToString());
}
}
补充:.NET技术 , ASP.NET