I have seen many articles for DataList custom paging, everyone showing paging in the DataList when the image is coming from a database. My requirement was for paging in a DataList when the image is coming from a folder.
This article demonstrates how to create custom paging for DataList control when the image is coming from a folder.
Step 1:
Design a Form; drag a DataList Control from the toolbox. Set the Repeated Column property and design the DataList control as you require. Add link buttons for next, prev, first and last images.
- <asp:DataList ID="DataList1" runat="server" RepeatColumns="4" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" Width="100% onselectedindexchanged=" DataList1_SelectedIndexChanged">
- <FooterStyle BackColor="#CCCCCC" />
- <SelectedItemStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
- <HeaderTemplate>
- <span class="style2">Image Gallary</span>
- </HeaderTemplate>
- <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
- <ItemTemplate>
- <asp:ImageButton Width="105px" ID="Image1" runat="server" BorderStyle="Solid" ImageUrl='<%# Bind("Name", "~/[foldername]/{0}") %>' CommandName="Image" CommandArgument='<%# Bind("Name") %>' Height="94px" />
- <br />
- <asp:Label ID="lblImg" Text='<%# Bind("Name") %>' runat="server" Visible="false" />
- <br />
- </ItemTemplate>
- <FooterStyle BackColor="White" ForeColor="#333333" />
- <ItemStyle BorderColor="Silver" BorderStyle="Dotted" BorderWidth="1px" HorizontalAlign="Center" VerticalAlign="Bottom" BackColor="White" ForeColor="#333333" />
- </asp:DataList>
- <asp:LinkButton ID="btnNext" runat="server" CausesValidation="False" onclick="btnNext_Click">Next ></asp:LinkButton>
- <asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False" onclick="btnFirst_Click"><< First
- </asp:LinkButton>
- <asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False" onclick="btnPrev_Click"><
- Prev</asp:LinkButton>
- <asp:LinkButton ID="btnLast" runat="server" CausesValidation="False" onclick="btnLast_Click">Last
- >></asp:LinkButton>
Step 2:
Write the following code...
Step 3: Run your website………………….