dotnetspider.com


 


TutorialsForumResourcesReviewsJobsInterviewVideosCommunitiesProjectsTraining

Subscribe to Subscribers


Online MembersSankar
Sunitha
Ashokkumar
Anu George
chanti
Falguni
Prachi Kulkarni
cloud
Prasad kulkarni
Gokula
Prabu Thangavelu
More...




Resources » Code Snippets » Databinding


Paging of Data list


Posted Date:     Category: Databinding    Rating: 1 out of 5
Author: Member Level: Gold    Points: 10 (Rs 10)


When you have datalist there is one main problem in it and that is paging.. because paging is not allowed in data list.. You can solve this problem using this method...

On .aspx page.
we have create datalist with images.


<asp:DataList runat="server" id="datalist1" RepeatColumns="4" RepeatDirection="Horizontal">
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<img src="<%=DataBinder.Eval(Container.DataItem,"Image_name")%>" width="90" height="90">
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>

we have take two linkbutton for next and previous button for using paging..

<table border="0" width="410">
<tr>
<td align="left">
<asp:LinkButton ID="lbPrev" Runat="server">
Prev
</asp:LinkButton>
</td>
<td align="right">
<asp:LinkButton ID="lbNext" Runat="server">
Next
</asp:LinkButton>
</td>
</tr>
</table>


on .aspx.cs page...

binddatalist()
{
// use PageDatasource object for paging purpose..

PagedDataSource Page = new PagedDataSource();
try
{

DataSet ds = ds // ds is your datasource..
Page.AllowPaging = true;

//page object store the datasource of datalist..
Page.DataSource = ds.Tables[0].DefaultView;
Page.PageSize = 8;

//"CurrentPage" is global variable that content the current page index..
Page.CurrentPageIndex = CurrentPage;

dlGallery.DataSource = Page;
dlGallery.DataKeyField = "Image_ID";
dlGallery.DataBind();
//now datalist only show the a images...
//due to "Page.PageSize = 8;" statement...

//visible true or false of next and previous button
//according to last and first page...
lbtnNext.Enabled = !objPage.IsLastPage;
lbtnPrev.Enabled = !objPage.IsFirstPage;
}

catch(Exception ex)
{
throw ex;
}

}

then we have maintain paging using link and next button as below...

private void lbPrev_Click(object sender, System.EventArgs e)

{
CurrentPage -=1;
//"CurrentPage" is global variable that content the current page index..
BindList();
}

private void lbNext_Click(object sender, System.EventArgs e)

{
CurrentPage +=1;
//"CurrentPage" is global variable that content the current page index..
BindList();
}

Now your paging will be solve...

regards
varun bansal


Did you like this resource? Share it with your friends and show your love!





Responses to "Paging of Data list"
Author: Nisar    21 Apr 2009Member Level: Gold   Points : 1
Hey i want to use your code for paging but i few thing are missing

dlGallery=?
objPage=?
BindList()?
Where are the defination of there variable and functions, please attach working code if possible



Author: Padmaja    11 Dec 2009Member Level: Bronze   Points : 0
Thanks a lot because today this code helped me a lot


Author: Tim Edmonson    30 Aug 2010Member Level: Bronze   Points : 2
Thank you for this information! I looked through many options for paging of a DataList and they all seemed like poor work-arounds. This option using the PagedDataSource by far seems like the cleanest and most efficient option.

Hopefully a near future version of .NET includes paged datalist options as a default. Certainly seems like a common feature that people would be in need of.



Author: Pal (Parthiv) Patel    31 Aug 2010Member Level: Gold   Points : 1
hey varun

this one is awesome code snippet

keep it up

put good codes and earn money and points

give your presentation in good way.



Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: dropdown Filling with TextField and Value Field
    Previous Resource: To fetch rows from datatable more faster
    Return to Resources
    Post New Resource
    Category: Databinding


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Data List paging using PagedDataSource  .  

    My Profile

    Active Members
    TodayLast 7 Daysmore...


    Awards & Gifts


    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds



    About Us    Trademark Disclaimer    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.