急!急!急!使用 DataList 控件,如何将图片绑定到数据库的表中
有两张表,一张是相册表:albumSno(用户) album_id(相册ID) album_name(相册名字) ...
张三 1 aa
张三 2 bb
张三 3 cc
李四 4 dd
王五 5 ee
王五 6 ee
另一张表:photos
album_id photo_id photo_url ....
1 1 photos/01.jpg
1 2 photos/02.jpg
1 3 photos/03.jpg
2 4 photos/04.jpg
2 5 photos/05.jpg
3 6 photos/06.jpg
3 7 photos/07.jpg
3 8 photos/08.jpg
下面是的XML文档,我使用的是DataList控件绑定数据:
<asp:DataList ID="DataList1" runat="server" CellSpacing="30" RepeatColumns="3">
<ItemTemplate>
<table>
<tr>
<td style="width: 188px; height: 146px" background="图片/相册背景.jpg">
<asp:Image ID="Image1" runat="server" Height="100" Width="100" ImageUrl='<%#Eval ("photo_url")%> '/>
</td>
</tr>
<tr>
<td style="width: 188px; height: 25px">
<asp:Label ID="Label1" runat="server" Text=""><%#Eval("album_name")%></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
下面是ASP。net 的代码页,实行对DataList的分页,要怎么对它进行处理,使它即能分页,又能显示出,每一个相册里面的第一张图片,让它做为相册的前景图片显示出来(就像QQ空间里的相册一下样,点击相册就能看到里面的所有照片)
public partial class myspace : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.num.Text = "1";
this.myphotos();
}
}
private void myphotos()
{
int curPage = (Convert.ToInt32(this.num.Text));
SqlConnection conn = new SqlConnection("server=.;database=photo_Data;Integrated Security=SSPI");
SqlDataAdapter da = new SqlDataAdapter("select a.album_id,a.album_name,a.album_id,b.photo_url from album as a , photos as b where a.album_id=b.album_id", conn);
DataSet ds = new DataSet();
da.Fill(ds, "album");
PagedDataSource ps = new PagedDataSource();
ps.DataSource = ds.Tables["album"].DefaultView;
ps.AllowPaging = true;
ps.PageSize = 6;
ps.CurrentPageIndex = curPage - 1;
this.previous.Enabled = true;
this.next.Enabled = true;
if (curPage == 1)
{
this.previous.Enabled = false;
}
if (curPage == ps.PageCount)
{
this.next.Enabled = false;
}
this.DataList1.DataSource = ps;
this.DataList1.DataBind();
}
protected void previous_Click(object sender, EventArgs e)
{
this.num.Text = Convert.ToString(Convert.ToInt32(this.num.Text) - 1);
this.myphotos();
}
protected void next_Click(object sender, EventArgs e)
{
this.num.Text = Convert.ToString(Convert.ToInt32(this.num.Text) +1);
this.myphotos();
}
请各位高手多多指教。。。。谢谢。。。。
[[it] 本帖最后由 寒行 于 2008-6-29 10:42 编辑 [/it]]