Hai,
I have a problem regarding DataGrid sorting.The grid is an userControl
The below event is not getting fired
Private Sub RepMsgGrd_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles RepMsgGrd.SortCommand
If Me.sortCriteria = e.SortExpression Then
If Me.sortDir = "desc" Then
Me.sortDir = "asc"
Else
Me.sortDir = "desc"
End If
End If
Me.sortCriteria = e.SortExpression
DisplayGrid()
End Sub
Kindly suggest me.
Thanks,
vskumarDo you have AllowSorting="True"
AND OnSortCommand="NameOfSortEventHandler" set on your datagrid?Ya.
and I have that event handler.
RepMsgGrd_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles RepMsgGrd.SortCommand
RepMsgGrd is the namId of the grid .
This is work in .aspx files but not work in .aspx files.I am setting
AllowSorting=True
AutoGenerateColumns=False
When I Set BoundColoumn at RunTime Sort evevnt not get fired.
Otherwise it will work.
any help pls?
Note: I am given that functions for your reference.
Public Sub DisplayGrid()
Dim Dt_RepMsgGrd As New DataTable
RepMsgGrd.Visible = True
Dt_RepMsgGrd = getGridData()
Me.RepMsgGrd.DataSource = Dt_RepMsgGrd
getGridColoumns(Dt_RepMsgGrd)
Me.RepMsgGrd.DataBind()
End Sub
Public Sub getGridColoumns(ByVal Dt_RepMsgGrd As DataTable)
Dim GridColoumnNameList As String
Dim GridColoumnName As String()
GridColoumnNameList = GridColNameList
GridColoumnName = Split(GridColoumnNameList, ",")
For i As Integer = 0 To GridColoumnName.Length - 1
Dim Bc_RepMsgGrd As New BoundColumn
strGridColFieldList(i) = Dt_RepMsgGrd.Columns(i).ColumnName
Bc_RepMsgGrd.DataField = Dt_RepMsgGrd.Columns(i).ColumnName
Bc_RepMsgGrd.SortExpression = Dt_RepMsgGrd.Columns(i).ColumnName
Bc_RepMsgGrd.HeaderText = GridColoumnName(i)
RepMsgGrd.Columns.Add(Bc_RepMsgGrd)
Next
End Sub
Public Sub RepMsgGrd_Sort(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs)
If Me.sortCriteria = e.SortExpression Then
If Me.sortDir = "desc" Then
Me.sortDir = "asc"
Else
Me.sortDir = "desc"
End If
End If
Me.sortCriteria = e.SortExpression
DisplayGrid()
End SubYou can also use orderby in the sql statement to sort a grid.set enableviewstate="true" of datagrid. sorting uses viewstate infoset enableviewstate="true" of datagrid. sorting uses viewstate info
I have a problem regarding DataGrid sorting.The grid is an userControl
The below event is not getting fired
Private Sub RepMsgGrd_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles RepMsgGrd.SortCommand
If Me.sortCriteria = e.SortExpression Then
If Me.sortDir = "desc" Then
Me.sortDir = "asc"
Else
Me.sortDir = "desc"
End If
End If
Me.sortCriteria = e.SortExpression
DisplayGrid()
End Sub
Kindly suggest me.
Thanks,
vskumarDo you have AllowSorting="True"
AND OnSortCommand="NameOfSortEventHandler" set on your datagrid?Ya.
and I have that event handler.
RepMsgGrd_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles RepMsgGrd.SortCommand
RepMsgGrd is the namId of the grid .
This is work in .aspx files but not work in .aspx files.I am setting
AllowSorting=True
AutoGenerateColumns=False
When I Set BoundColoumn at RunTime Sort evevnt not get fired.
Otherwise it will work.
any help pls?
Note: I am given that functions for your reference.
Public Sub DisplayGrid()
Dim Dt_RepMsgGrd As New DataTable
RepMsgGrd.Visible = True
Dt_RepMsgGrd = getGridData()
Me.RepMsgGrd.DataSource = Dt_RepMsgGrd
getGridColoumns(Dt_RepMsgGrd)
Me.RepMsgGrd.DataBind()
End Sub
Public Sub getGridColoumns(ByVal Dt_RepMsgGrd As DataTable)
Dim GridColoumnNameList As String
Dim GridColoumnName As String()
GridColoumnNameList = GridColNameList
GridColoumnName = Split(GridColoumnNameList, ",")
For i As Integer = 0 To GridColoumnName.Length - 1
Dim Bc_RepMsgGrd As New BoundColumn
strGridColFieldList(i) = Dt_RepMsgGrd.Columns(i).ColumnName
Bc_RepMsgGrd.DataField = Dt_RepMsgGrd.Columns(i).ColumnName
Bc_RepMsgGrd.SortExpression = Dt_RepMsgGrd.Columns(i).ColumnName
Bc_RepMsgGrd.HeaderText = GridColoumnName(i)
RepMsgGrd.Columns.Add(Bc_RepMsgGrd)
Next
End Sub
Public Sub RepMsgGrd_Sort(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs)
If Me.sortCriteria = e.SortExpression Then
If Me.sortDir = "desc" Then
Me.sortDir = "asc"
Else
Me.sortDir = "desc"
End If
End If
Me.sortCriteria = e.SortExpression
DisplayGrid()
End SubYou can also use orderby in the sql statement to sort a grid.set enableviewstate="true" of datagrid. sorting uses viewstate infoset enableviewstate="true" of datagrid. sorting uses viewstate info