Solved

Paging a DataList using

Posted on 2008-10-17
3
1,279 Views
Last Modified: 2013-11-07
I have a web page where I would like to display data tiled horizontally.  The problem is that my data will have over 3,000 records.  If I use the DataList data control, it does not allow for paging.  

Is there a way to convert my code listed below into some sort of pageable DataList?  Thanks in advance!
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"

        SelectCommand="SELECT * FROM Project WHERE (Orderable = '1')>

    </asp:SqlDataSource>

    <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" Width="100%"

        RepeatColumns="4" RepeatDirection="Horizontal" CellPadding="2" CellSpacing="2">

        <ItemTemplate>

            <itemtemplate>

                    <asp:Image ID="Image2" runat="server" Width="125px" ImageUrl='<%# Eval("ID", "ImageLoader.ashx?id={0}") %>' />

                    <br />

                    <%# DataBinder.Eval(Container.DataItem, "Name")%>

                    <br /><br />

                    Amount:&nbsp;&nbsp;<%# DataBinder.Eval(Container.DataItem, "Amount")%>

                </itemtemplate>

        </ItemTemplate>

        <ItemStyle Font-Size="10px" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" />

    </asp:DataList>

Open in new window

0
Comment
Question by:deloused
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
jinn_hnnl earned 500 total points
ID: 22743707
Yes DataList has no paging mechanism. You gotta make it your own, there are several ways. But the best way you can do is Binding your Datalist datasource dynamically.

http://forums.asp.net/t/1319544.aspx

You can use SqlDataAdapter, the SqlDataAdapter allow you to select and get data upon start and number of record you want to return. Try to remember the page number using ViewState and using when you fill the dataSet

Hope this helps

JINN






public DataTable getTheData()

    {
 

        DataSet DS = new DataSet();

        SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyProject"].ConnectionString);
 

        SqlDataAdapter objSQLAdapter = new SqlDataAdapter("SELECT * FROM Project WHERE (Orderable = '1'", myConnection); objSQLAdapter.Fill(DS, "Projects");
 
 

        return DS.Tables[0];
 

    }
 

    void doPaging()

    {
 

        pagedData.DataSource = getTheData().DefaultView;
 

        pagedData.AllowPaging = true;

        pagedData.PageSize = 4;

Open in new window

0
 

Author Comment

by:deloused
ID: 22743892
Awesome. That was exactly what I was looking for.  
0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22744254
Cool,

I am glad to help ^^

JINN
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now