RadControls version 2011.3.1305.35
I have a very simple RadGrid example that allows column sorting. I have added checkboxes to each column header. I am experiencing 2 issues when attempting to sort. The 1st, 3rd, 5th, ... (every other time) times that I click on the column header, my checkboxes disappear and the data does not sort. This is undesired behavior. The 2nd, 4th, 6th, ... times that I click on the column header, it sorts as expected and my checkboxes are visible as expected. What I would like to accomplish is:
#1 - Everytime I click on a column header, the grid sorts. I would expect the SortCommand event to get raised each time.
#2 - Everytime I click on a column header, the checkboxes are visible.
Please watch this video clip to see the what I have decribed as the issue. I would expect my breakpoint to be hit on every column sort.
http://screencast.com/t/V8OTlSGMdXSL
Here is my code:
Thanks.
I have a very simple RadGrid example that allows column sorting. I have added checkboxes to each column header. I am experiencing 2 issues when attempting to sort. The 1st, 3rd, 5th, ... (every other time) times that I click on the column header, my checkboxes disappear and the data does not sort. This is undesired behavior. The 2nd, 4th, 6th, ... times that I click on the column header, it sorts as expected and my checkboxes are visible as expected. What I would like to accomplish is:
#1 - Everytime I click on a column header, the grid sorts. I would expect the SortCommand event to get raised each time.
#2 - Everytime I click on a column header, the checkboxes are visible.
Please watch this video clip to see the what I have decribed as the issue. I would expect my breakpoint to be hit on every column sort.
http://screencast.com/t/V8OTlSGMdXSL
Here is my code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="RadGridSorting.aspx.vb" Inherits="RadGridSorting" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
telerik:RadScriptManager
runat
=
"server"
ID
=
"mgrJS"
>
</
telerik:RadScriptManager
>
<
telerik:RadGrid
runat
=
"server"
ID
=
"dgHeader"
Skin
=
"Web20"
AllowSorting
=
"true"
>
<
ClientSettings
>
<
Scrolling
UseStaticHeaders
=
"True"
/>
<
Selecting
EnableDragToSelectRows
=
"False"
/>
</
ClientSettings
>
<
MasterTableView
BorderWidth
=
"1px"
GridLines
=
"Both"
style
=
"border-collapse: collapse !Important;"
Font-Bold
=
"false"
TableLayout
=
"Fixed"
AutoGenerateColumns
=
"false"
ShowHeader
=
"True"
>
<
RowIndicatorColumn
Visible
=
"False"
>
<
HeaderStyle
Width
=
"20px"
/>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
Resizable
=
"False"
Visible
=
"False"
>
<
HeaderStyle
Width
=
"20px"
/>
</
ExpandCollapseColumn
>
<
EditFormSettings
>
<
PopUpSettings
ScrollBars
=
"None"
/>
</
EditFormSettings
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
form
>
</
body
>
</
html
>
Partial
Class
RadGridSorting
Inherits
System.Web.UI.Page
Protected
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.Load
If
Not
Page.IsPostBack
Then
Dim
dtHeader
As
New
DataTable
dtHeader.Columns.Add(
New
DataColumn(
"COL_ID"
,
GetType
(
String
)))
Dim
colRow
As
DataRow = dtHeader.NewRow
colRow(0) =
"1234567"
dtHeader.Rows.Add(colRow)
colRow = dtHeader.NewRow
colRow(0) =
"2345678"
dtHeader.Rows.Add(colRow)
colRow = dtHeader.NewRow
colRow(0) =
"3456789"
dtHeader.Rows.Add(colRow)
colRow = dtHeader.NewRow
colRow(0) =
"4567890"
dtHeader.Rows.Add(colRow)
colRow = dtHeader.NewRow
colRow(0) =
"5678901"
dtHeader.Rows.Add(colRow)
colRow = dtHeader.NewRow
colRow(0) =
"6789012"
dtHeader.Rows.Add(colRow)
colRow = dtHeader.NewRow
colRow(0) =
"7890123"
dtHeader.Rows.Add(colRow)
'Define columns of master table view.
For
Each
row
As
DataRow
In
dtHeader.Rows
Dim
newCol
As
New
GridBoundColumn
dgHeader.MasterTableView.Columns.Add(newCol)
newCol.HeaderText = row(
"COL_ID"
)
newCol.DataField = row(
"COL_ID"
)
newCol.DataFormatString =
"{0:N0}"
newCol.HeaderStyle.Width = 100
newCol.ItemStyle.Width = 100
Next
Session(
"header"
) = dtHeader
End
If
End
Sub
Protected
Sub
dgHeader_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridItemEventArgs)
Handles
dgHeader.ItemDataBound
If
e.Item.ItemType = GridItemType.Header
Then
Dim
hdrItem
As
GridHeaderItem =
CType
(e.Item, GridHeaderItem)
For
i
As
Integer
= 2
To
hdrItem.Cells.Count - 1
Dim
ctrl
As
LinkButton =
CType
(hdrItem.Cells(i).Controls(0), LinkButton)
If
ctrl IsNot
Nothing
Then
Dim
val
As
Integer
= 0
Integer
.TryParse(ctrl.Text, val)
If
val > 0
Then
Dim
chk
As
New
CheckBox
chk.ID =
"chk"
& val
hdrItem.Cells(i).Controls.Clear()
hdrItem.Cells(i).Controls.Add(chk)
hdrItem.Cells(i).Controls.Add(ctrl)
hdrItem.Cells(i).HorizontalAlign = HorizontalAlign.Center
End
If
End
If
Next
End
If
End
Sub
Protected
Sub
dgHeader_NeedDataSource(
ByVal
source
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridNeedDataSourceEventArgs)
Handles
dgHeader.NeedDataSource
If
Session(
"data"
)
Is
Nothing
Then
Session(
"data"
) = CreateTable()
End
If
dgHeader.DataSource = Session(
"data"
)
End
Sub
Private
Function
CreateTable()
As
DataTable
Dim
dtHeader
As
DataTable = Session(
"header"
)
Dim
dtData
As
New
DataTable
For
Each
dr
As
DataRow
In
dtHeader.Rows
dtData.Columns.Add(
New
DataColumn(dr(
"COL_ID"
),
GetType
(
Integer
)))
Next
'Populate w/ data
Dim
Generator
As
System.Random =
New
System.Random()
Dim
r
As
DataRow
For
i
As
Integer
= 0
To
9
r = dtData.NewRow
For
j
As
Integer
= 0
To
6
r(j) = Generator.
Next
(0, 100)
Next
dtData.Rows.Add(r)
Next
Return
dtData
End
Function
Protected
Sub
dgHeader_SortCommand(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridSortCommandEventArgs)
Handles
dgHeader.SortCommand
Dim
s
As
String
=
""
End
Sub
End
Class
Thanks.