|
Should this bit be updated? I am getting weird paged items. IE if I put page size 1 I get 2. THe ItemIndex should be < not <=. Does this make sense?
if (item.ItemIndex >= (int)ViewState["_startRowIndex"] &&
item.ItemIndex < ((int)ViewState["_startRowIndex"] +
(int)ViewState["_maximumRows"]))
{
item.Visible = true;
}
|
|
|
|
|
The following code will guide you how to work with databind when not using presistentDataSource.
In default.aspx.cs (the codebehind file) of the download code example.
Replace entire page code with this and you see how it works.
There are also an example when using datasource paging:
Uncomment the parts under
////***DATASOURCE PAGING***
and comment the parts under
//**PAGING IN REPEATER ALWAYS LOAD DATA PersistentDataSource = false;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
private int currentIndex;
protected void Page_Load(object sender, EventArgs e)
{
rep1.FetchingData += new EventHandler<PageEventArgs>(rep1_FetchingData);
rep1.PreRender += new EventHandler(rep1_PreRender);
if
(!IsPostBack)
{
rep1.PersistentDataSource = false;
System.Collections.SortedList SL = new System.Collections.SortedList();
rep1.PagingInDataSource = false;
SL.Add("val0", "Text0");
SL.Add("val1", "Text1");
SL.Add("val2", "Text2");
SL.Add("val3", "Text3");
SL.Add("val4", "Text4");
SL.Add("val5", "Text5");
SL.Add("val6", "Text6");
SL.Add("val7", "Text7");
SL.Add("val8", "Text8");
SL.Add("val9", "Text9");
SL.Add("val10", "Text10");
rep1.DataSource = SL;
rep1.DataBind();
}
}
protected void rep1_TotalRowCountAvailable(object sender, PageEventArgs e)
{
}
protected void rep1_FetchingData(object sender, PageEventArgs e)
{
currentIndex = rep1.StartRowIndex;
System.Collections.SortedList SL = new System.Collections.SortedList();
SL.Add("val0", "Text0");
SL.Add("val1", "Text1");
SL.Add("val2", "Text2");
SL.Add("val3", "Text3");
SL.Add("val4", "Text4");
SL.Add("val5", "Text5");
SL.Add("val6", "Text6");
SL.Add("val7", "Text7");
SL.Add("val8", "Text8");
SL.Add("val9", "Text9");
SL.Add("val10", "Text10");
rep1.DataSource = SL;
rep1.DataBind();
}
void rep1_PreRender(object sender, EventArgs e)
{
if (currentIndex != rep1.StartRowIndex)
{
System.Collections.SortedList SL = new System.Collections.SortedList();
SL.Add("val0", "Text0");
SL.Add("val1", "Text1");
SL.Add("val2", "Text2");
SL.Add("val3", "Text3");
SL.Add("val4", "Text4");
SL.Add("val5", "Text5");
SL.Add("val6", "Text6");
SL.Add("val7", "Text7");
SL.Add("val8", "Text8");
SL.Add("val9", "Text9");
SL.Add("val10", "Text10");
rep1.DataSource = SL;
rep1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
}
}
|
|
|
|
|
hello
this is very well demo on datapager with repeater but very slow while switching between pages.
if you have any solution to it, it will work better.
|
|
|
|
|
There may be many things. But there is one thing you can try directly in the control.
Try changing PersistentDataSource = true / false. PresistentDataSource saves all the data in the view state, which can cause the page to grow very large and very slow.
PresistetDataSource can also make things faster if it takes a long time to download the data from the data source
|
|
|
|
|
i have tried it but its not working with PersistentDataSource="true" its not switching the page on link or button click.
|
|
|
|
|
Check the example code first repeater is using PresistentDataSource = true
|
|
|
|
|
i have tried it with PresistentDataSource = true its working well but taking too much time on sever otherwise it working very well in local also
and with PresistentDataSource = false its not switching the page
you can check in my website how its working at www.yarnsvalley.com
|
|
|
|
|
The following code will guide you to how to work with databind when not using presistentDataSource
In default.aspx.cs (the codebehind file) of the download example.
Replace entire page code with this and you see how it works.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
private int currentIndex;
protected void Page_Load(object sender, EventArgs e)
{
rep1.FetchingData += new EventHandler<PageEventArgs>(rep1_FetchingData);
rep1.PreRender += new EventHandler(rep1_PreRender);
if
(!IsPostBack)
{
rep1.PersistentDataSource = false;
System.Collections.SortedList SL = new System.Collections.SortedList();
rep1.PagingInDataSource = false;
SL.Add("val0", "Text0");
SL.Add("val1", "Text1");
SL.Add("val2", "Text2");
SL.Add("val3", "Text3");
SL.Add("val4", "Text4");
SL.Add("val5", "Text5");
SL.Add("val6", "Text6");
SL.Add("val7", "Text7");
SL.Add("val8", "Text8");
SL.Add("val9", "Text9");
SL.Add("val10", "Text10");
rep1.DataSource = SL;
rep1.DataBind();
}
}
protected void rep1_TotalRowCountAvailable(object sender, PageEventArgs e)
{
}
protected void rep1_FetchingData(object sender, PageEventArgs e)
{
currentIndex = rep1.StartRowIndex;
System.Collections.SortedList SL = new System.Collections.SortedList();
SL.Add("val0", "Text0");
SL.Add("val1", "Text1");
SL.Add("val2", "Text2");
SL.Add("val3", "Text3");
SL.Add("val4", "Text4");
SL.Add("val5", "Text5");
SL.Add("val6", "Text6");
SL.Add("val7", "Text7");
SL.Add("val8", "Text8");
SL.Add("val9", "Text9");
SL.Add("val10", "Text10");
rep1.DataSource = SL;
rep1.DataBind();
}
void rep1_PreRender(object sender, EventArgs e)
{
if (currentIndex != rep1.StartRowIndex)
{
System.Collections.SortedList SL = new System.Collections.SortedList();
SL.Add("val0", "Text0");
SL.Add("val1", "Text1");
SL.Add("val2", "Text2");
SL.Add("val3", "Text3");
SL.Add("val4", "Text4");
SL.Add("val5", "Text5");
SL.Add("val6", "Text6");
SL.Add("val7", "Text7");
SL.Add("val8", "Text8");
SL.Add("val9", "Text9");
SL.Add("val10", "Text10");
rep1.DataSource = SL;
rep1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
}
}
|
|
|
|
|
hi
its solved my problem now my site working fast with paging
thank you very much for your guide
|
|
|
|
|
In the download code you can see an example of using persistentdatasource
|
|
|
|
|
Hi,
First of all, thank you very much for your post. It help me a lot. However, I am wondering is this applicable to nested repeater?
Thanks,
ST
|
|
|
|
|
Hi, thanks for your article!
But I faced with a problem. DataBind is calling on Load. And so, if I want to get values of controls placed in Repeater, I can't. Values are null, because DataBind is calling on Load.
I need to get checked checkboxes in repeater on postback (clicking 'Delete' in my case).
So, could you help me to deal with this problem? Any suggestions?
|
|
|
|
|
In your postback event, you first need to bind the data to the repeater again. Then the controls will be created and you can read from them.
|
|
|
|
|
hi
i use 3 layer architecture in my project and when i use this dataPager in it occurrence the following error, in .net 4
Type 'BLL.SpecialAds' in Assembly 'BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
|
|
|
|
|
The property PersistentDataSource = true will try to cache your data bll.SpecialAds into the page viewstate (so you don't have to reload the repeater with new data for each page click). You can solve this by adding the attribute "serializable" to the bll.specialAds class OR you can set the PersistentDataSource to False but then you need to reload the data at every page click
|
|
|
|
|
|
How can I use it with SqlDataReader?
|
|
|
|
|
Like this:
yourRepObj.DataSource = yourSQLdata;
yourRepObj.DataBind();
Download the the new sourcecode it is updated after you wrote your question
But this is a very old article, so if you can use the ListView then use it instead
|
|
|
|
|
I implemented sorting with this - but found the datarepeater was displaying data from one click ago - even though the datasource is correct and the databind is done just after. - I belive it may have something to do with the persistent datasource - but when I turn that off I get a null returned from GetData().
Has anybody else come across this? How do I fix the issue?
-cheers in advance.
|
|
|
|
|
|
Excellent work. Exactly what i was looking for. Thank you so much. Amazing this isnt a part of .NET already. It should DEFINITELY be on CodePlex.
|
|
|
|
|
Hi,
First off, thanks for the great example. It's almost exactly what I needed.
I'm trying to implement the version of the control that you have at http://www.publech.com/DataPagerRepeater.zip[^].
My understanding is that when the FetchingData event is raised, I should re-bind the repeater with the next or previous page of data and set the total records. The problem I'm having is that that the FetchingData event is raised before the new StartRowIndex value is set by the DataPager so essentially, all I can do is rebind the previous page of data.
What I ended up doing is checking for IsPostBack in the SetPageProperties method (because it seems that the DataPager eventually calls it) and doing the same checks you did in OnLoad then calling FetchingData there. Paging now works correctly with the intended page of data but only because FetchData is now called twice, thus doubling my calls to the database.
Is this working for anyone? Is there a way call FetchingData only after the new page index has been set by the DataPager?
Thanks,
Chad
|
|
|
|
|
Well, for anyone who cares (apparently no one), I did away with the Fetching data event altogether and bound my data in two places:
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
BindData(1) ' Pass Page Number
End If
End Sub
And on the PreRender event of the DataPager control itself as this is about the only place you can be guaranteed that the proper page indexes have been set:
Private Sub DataPager1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataPager1.PreRender
If Page.IsPostBack Then ' Already bound on page load.
BindData(rep1.StartRowIndex + 1) ' Pass Page Number
End If
End Sub
The page now behaves as expected.
I've seen other articles using this same approach, even with the ListView and a DataPager and this is what ultimately works for this control as well.
Chad
|
|
|
|
|
I'm having a problem when using DataPagerRepeater inside an Update Panel.
What happens is that on a button I rebind the repeater to a new data source and calls the update panel update().
The bug is that the repeater isn't update with the new data.
I've traced the databind function and what happens is that on the GetData() function I get the old data and it is not being replaced with the DataSource property.
Can you please fix it?
Thanks.
|
|
|
|
|
|