Hello Support,
I tried searching forums regarding the itemdatabound event being fired twice for a radgrid. But no solutions proved conclusive. So I have created an example project with a single page.
1 RadScriptManager
1 SQLDataSource
1 RadGrid (Telerik v 2015.2.826.45)
SQLDatasource connecting to a table with 5 rows
id desc percent
1 A 10
2 B 20
3 C 30
4 D 40
5 E 50
ItemDataBound was seen to fire 12 times twice for each row. (+1 for header and +1 for footer)
Please explain how can I restrict this to fire once for each row.
Code for .vb , .aspx are included. The example project is also attached along with screenshots for runtime and database.
.vb
Imports
Telerik.Web.UI
Public
Class
_default
Inherits
System.Web.UI.Page
Protected
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.Load
Session(
"ctr"
) = 0
End
Sub
Private
Sub
RadGrid1_ItemDataBound(sender
As
Object
, e
As
GridItemEventArgs)
Handles
RadGrid1.ItemDataBound
Session(
"ctr"
) += 1
Debug.WriteLine(
"ItemDataBound: "
& Session(
"ctr"
))
End
Sub
End
Class
.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="default.aspx.vb" Inherits="RadGrid_ItemDatabound._default" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<!DOCTYPE html>
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
Runat
=
"server"
>
</
telerik:RadScriptManager
>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:MySQLConnectionString %>" ProviderName="<%$ ConnectionStrings:MySQLConnectionString.ProviderName %>" SelectCommand="Select * from temp"></
asp:SqlDataSource
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
CellSpacing
=
"-1"
DataSourceID
=
"SqlDataSource1"
GridLines
=
"Both"
GroupPanelPosition
=
"Top"
>
<
MasterTableView
AutoGenerateColumns
=
"False"
DataSourceID
=
"SqlDataSource1"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"id"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter id column"
HeaderText
=
"id"
SortExpression
=
"id"
UniqueName
=
"id"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"desc"
FilterControlAltText
=
"Filter desc column"
HeaderText
=
"desc"
SortExpression
=
"desc"
UniqueName
=
"desc"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"percent"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter percent column"
HeaderText
=
"percent"
SortExpression
=
"percent"
UniqueName
=
"percent"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
div
>
</
form
>
</
body
>
</
html
>
Debug Output:
ItemDataBound: 1
ItemDataBound: 2
ItemDataBound: 3
ItemDataBound: 4
ItemDataBound: 5
ItemDataBound: 6
ItemDataBound: 7
ItemDataBound: 8
ItemDataBound: 9
ItemDataBound: 10
ItemDataBound: 11
ItemDataBound: 12