-1
中繼器不能訪問數據庫,我如何設置當前顯示圖像,例如,如果我有20圖像,第一頁,我想只顯示10圖像。現在我將從文件夾中獲取整個圖像。中繼器不能從數據庫訪問
<asp:Repeater ID="Repeater1" runat="server" >
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" ImageUrl='<%#"Images/" + Eval("Name") %>' CssClass="img img-responsive thumbnail center-block " runat="server" width="234px" height="250px" ToolTip="check to buy" />
</ItemTemplate>
</asp:Repeater>
</div>
前頁 下一頁
private void ListImages(int SelectedPage)
{
DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/Images"));
FileInfo[] file = dir.GetFiles();
ArrayList list = new ArrayList();
foreach (FileInfo info in file)
{
if (info.Extension == ".jpg" || info.Extension == ".jpeg" || info.Extension == ".gif" || info.Extension == ".png")
{
list.Add(info);
}
}
Repeater1.DataSource = list;
Repeater1.DataBind();
// Step 2: Create PagedDataSource instance and set its properties
PagedDataSource pds = new PagedDataSource();
pds.DataSource = list;
pds.AllowPaging = true;
pds.PageSize = 2;
if (SelectedPage > (pds.PageCount - 1))
{
SelectedPage = pds.PageCount - 1;
}
if (SelectedPage < 0)
SelectedPage = 0;
pds.CurrentPageIndex = SelectedPage;
// Step 3: Bind PagedDataSource to Repeater and set LinkButtons' behavior
Repeater1.DataSource = pds;
if (pds.IsLastPage)
lbNext.Enabled = false;
else
lbNext.Enabled = true;
if (pds.IsFirstPage)
lbPrevious.Enabled = false;
else
lbPrevious.Enabled = true;
}