Hello,
I have run into a problem where the ItemDataBound event is fired multiple times whenever the "next page" link is clicked and SEO paging is enabled. But the weird thing is that the first time, it's fired for the items on the first page! The sequence goes like this, once the user clicks "next page":
If I turn off SEO paging, it works as expected
I am not really sure what I am doing wrong. Here's a sample code to demonstrate:
ASPX
code behind:
I have run into a problem where the ItemDataBound event is fired multiple times whenever the "next page" link is clicked and SEO paging is enabled. But the weird thing is that the first time, it's fired for the items on the first page! The sequence goes like this, once the user clicks "next page":
- page load
- need data source
- item data bound for each item on the first page
- pre render
- item data bound for each item on the new page
If I turn off SEO paging, it works as expected
- page load
- need data sourec
- item data bound for each item on the new page
- pre render
I am not really sure what I am doing wrong. Here's a sample code to demonstrate:
ASPX
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowPaging
=
"True"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
OnPreRender
=
"RadGrid1_PreRender"
PageSize
=
"5"
onneeddatasource
=
"RadGrid1_NeedDataSource"
>
<
MasterTableView
DataKeyNames
=
"doc_id"
>
</
MasterTableView
>
<
PagerStyle
EnableSEOPaging
=
"true"
SEOPagingQueryStringKey
=
"page"
/>
</
telerik:RadGrid
>
code behind:
public
partial
class
_Default : System.Web.UI.Page
{
public
class
TestData
{
public
int
doc_id{
get
;
set
;}
public
string
Title{
get
;
set
;}
}
private
List<TestData> GetData()
{
var data =
new
List<TestData>();
for
(
int
i = 1; i < 30; i++) {data.Add(
new
TestData(){doc_id = i,Title =
"Title for "
+ i});}
return
data;
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
Debug.WriteLine(
"Pageload"
);
}
protected
void
RadGrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
Debug.WriteLine(
"ItemDataBound: "
+ (e.Item
as
GridDataItem).GetDataKeyValue(
"doc_id"
));
}
}
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
Debug.WriteLine(
"PreRender"
);
}
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
Debug.WriteLine(
"NeedDataSource"
);
RadGrid1.DataSource = GetData();
}
}