hi,
in my application i create the columns of a datagrid at runtime (excep the first one). I allow sorting on datagrid but when i try to sort the datagrid gets empty.
This is the code i wrote :
Private Sub CreateDataGrid()
Dim boundCol As BoundColumn
While dgPreview.Columns.Count > 1
dgPreview.Columns.RemoveAt(dgPreview.Columns.Count - 1)
End While
With dgPreview
.AllowSorting = True
.AutoGenerateColumns = False
.DataKeyField = "Id"
boundCol = New BoundColumn
boundCol.DataField = "Id"
boundCol.Visible = False
.Columns.Add(boundCol)
' add other columns
' add handler
AddHandler dgPreview.SortCommand, AddressOf dgPreview_SortCommand
end sub
Private Sub dgPreview_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs)
CreateDataGrid()
BindDataGrid()
End Sub
in my application i create the columns of a datagrid at runtime (excep the first one). I allow sorting on datagrid but when i try to sort the datagrid gets empty.
This is the code i wrote :
Private Sub CreateDataGrid()
Dim boundCol As BoundColumn
While dgPreview.Columns.Count > 1
dgPreview.Columns.RemoveAt(dgPreview.Columns.Count - 1)
End While
With dgPreview
.AllowSorting = True
.AutoGenerateColumns = False
.DataKeyField = "Id"
boundCol = New BoundColumn
boundCol.DataField = "Id"
boundCol.Visible = False
.Columns.Add(boundCol)
' add other columns
' add handler
AddHandler dgPreview.SortCommand, AddressOf dgPreview_SortCommand
end sub
Private Sub dgPreview_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs)
CreateDataGrid()
BindDataGrid()
End Sub