I am building a Custom Web control which inherits the gridview. I am doing this so I can add a defaultsortexpression for the gridview so I can set the sort order before any of the header links are clicked. I am connecting my custom gridview to an objectdatasoruce,
which should allow support sorting, however, when I look at the page in design view, the custom gridview has a message saying that "There was an error rendering the control. The data source does not support sorting" I am posting my code below. I'd appreciate
any assistance. Thanks in advance!
Custom Control Code in a file I have named CustGridView.vb
Imports Microsoft.VisualBasic
Namespace CustControls
Public Class CustGridView
Inherits System.Web.UI.WebControls.GridView
<ComponentModel.Browsable(True)> _
<ComponentModel.Description("Default Sort BLOCKED EXPRESSION")> _
<ComponentModel.Category("Behavior")> _
Public Property DefaultSortExpression() As String
Get
Dim TheDefaultSortExpression As String = CType(Me.ViewState("DefaultSortExpression"), String)
If TheDefaultSortExpression Is DBNull.Value Then
Return String.Empty
End If
Return TheDefaultSortExpression
End Get
Set(ByVal value As String)
Me.ViewState("DefaultSortExpression") = value
End Set
End Property
<ComponentModel.Browsable(True)> _
<ComponentModel.Description("Default Sort BLOCKED EXPRESSION")> _
<ComponentModel.Category("Behavior")> _
Public Property DefaultSortDirection() As SortDirection
Get
Dim TheDefaultSortDirection As Object = Me.ViewState("SortDirection")
If TheDefaultSortDirection Is Nothing Then
Return WebControls.SortDirection.Ascending
End If
Return CType(TheDefaultSortDirection, SortDirection)
End Get
Set(ByVal value As SortDirection)
End Set
End Property
Protected Overrides Function CreateDataSourceSelectArguments() As DataSourceSelectArguments
Dim TheDataSourceSelectArguments As DataSourceSelectArguments = MyBase.CreateDataSourceSelectArguments
If String.IsNullOrEmpty(TheDataSourceSelectArguments.SortExpression) And String.IsNullOrEmpty(Me.DefaultSortExpression) = False Then
TheDataSourceSelectArguments.SortExpression = Me.DefaultSortExpression
If Me.DefaultSortDirection = WebControls.SortDirection.Ascending Then
TheDataSourceSelectArguments.SortExpression += " ASC"
Else
TheDataSourceSelectArguments.SortExpression += " DESC"
End If
End If
Return TheDataSourceSelectArguments
End Function
End Class
End Namespace
.aspx code I am putting the custom gridview in named t.aspx
cartch
Member
158 Points
49 Posts
Custom Gridview Control
Oct 12, 2006 06:56 PM|LINK
I am building a Custom Web control which inherits the gridview. I am doing this so I can add a defaultsortexpression for the gridview so I can set the sort order before any of the header links are clicked. I am connecting my custom gridview to an objectdatasoruce, which should allow support sorting, however, when I look at the page in design view, the custom gridview has a message saying that "There was an error rendering the control. The data source does not support sorting" I am posting my code below. I'd appreciate any assistance. Thanks in advance!
Custom Control Code in a file I have named CustGridView.vb
Imports Microsoft.VisualBasic Namespace CustControls Public Class CustGridView Inherits System.Web.UI.WebControls.GridView <ComponentModel.Browsable(True)> _ <ComponentModel.Description("Default Sort BLOCKED EXPRESSION")> _ <ComponentModel.Category("Behavior")> _ Public Property DefaultSortExpression() As String Get Dim TheDefaultSortExpression As String = CType(Me.ViewState("DefaultSortExpression"), String) If TheDefaultSortExpression Is DBNull.Value Then Return String.Empty End If Return TheDefaultSortExpression End Get Set(ByVal value As String) Me.ViewState("DefaultSortExpression") = value End Set End Property <ComponentModel.Browsable(True)> _ <ComponentModel.Description("Default Sort BLOCKED EXPRESSION")> _ <ComponentModel.Category("Behavior")> _ Public Property DefaultSortDirection() As SortDirection Get Dim TheDefaultSortDirection As Object = Me.ViewState("SortDirection") If TheDefaultSortDirection Is Nothing Then Return WebControls.SortDirection.Ascending End If Return CType(TheDefaultSortDirection, SortDirection) End Get Set(ByVal value As SortDirection) End Set End Property Protected Overrides Function CreateDataSourceSelectArguments() As DataSourceSelectArguments Dim TheDataSourceSelectArguments As DataSourceSelectArguments = MyBase.CreateDataSourceSelectArguments If String.IsNullOrEmpty(TheDataSourceSelectArguments.SortExpression) And String.IsNullOrEmpty(Me.DefaultSortExpression) = False Then TheDataSourceSelectArguments.SortExpression = Me.DefaultSortExpression If Me.DefaultSortDirection = WebControls.SortDirection.Ascending Then TheDataSourceSelectArguments.SortExpression += " ASC" Else TheDataSourceSelectArguments.SortExpression += " DESC" End If End If Return TheDataSourceSelectArguments End Function End Class End Namespace.aspx code I am putting the custom gridview in named t.aspxrajbk
Participant
1173 Points
132 Posts
Re: Custom Gridview Control
Oct 13, 2006 01:48 AM|LINK
Why don't you want to use the GridView.Sort method to set the initial sort direction?
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sort.aspx
http://weblogs.asp.net/rajbk/
cartch
Member
158 Points
49 Posts
Re: Custom Gridview Control
Oct 13, 2006 09:43 AM|LINK
rajbk
Participant
1173 Points
132 Posts
Re: Custom Gridview Control
Oct 13, 2006 12:16 PM|LINK
To set the initial sort direction, you can fire this on Page_Load. Something like this
if (! IsPostback) {
GridView.Sort(....);
}
http://weblogs.asp.net/rajbk/
cartch
Member
158 Points
49 Posts
Re: Custom Gridview Control
Oct 13, 2006 01:34 PM|LINK