asp.netpaginationdatalist

Showing image in datalist asp.net


I am using datalist to show images. I want to show images like this

**image image image** I am getting only 1 row
image image image
image image image
image image image

Means, three column and 4 rows. I have below setting but I am getting one row only, how can I get 4 rows per page?

 <asp:DataList Style="border-bottom: 1px solid" ID="ImageList" runat="server" 
                    CssClass="mytable2" 
                 RepeatDirection="Horizontal">

Code behind:

 PagedDataSource objPds = new PagedDataSource();
        objPds.DataSource = productImageList.DefaultView;
        objPds.AllowPaging = true;
        objPds.PageSize = 3;
        objPds.CurrentPageIndex = CurrentPage;


        cmdPrev.Enabled = !objPds.IsFirstPage;
        cmdNext.Enabled = !objPds.IsLastPage;

        ImageList.RepeatColumns = 5;
        ImageList.RepeatLayout = RepeatLayout.Table;
        ImageList.DataSource = objPds;
        ImageList.DataBind();

Where productImageList is a dataset.


Solution

  • Issue is that you are using PageSize of 3 which means your data-list will get only 3 records to display. You need to select PageSize = 12 (3 columns x 4 rows).

    objPds.PageSize = 12;
    

    And lastly, for 3 columns in data list, you need to have ImageList.RepeatColumns = 3; or adjust page size accordingly to your rows and columns.