C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Databinding »

Paging of Data list


Posted Date: 11 Nov 2008    Resource Type: Code Snippets    Category: Databinding
Author: Varun BansalMember Level: Gold    
Rating: 1 out of 5Points: 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




Responses

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


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Data List paging using PagedDataSource  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: dropdown Filling with TextField and Value Field
Previous Resource: To fetch rows from datatable more faster
Return to Discussion Resource Index
Post New Resource
Category: Databinding


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use