barleywine
Programmer
I want to sort a datagrid which has 5 columns by either of the first three. I am already paging the datagrid. I don't need to update the underlying recordset, just display sorted tables on the web page.
The Column names I want to sort on are: Species, Contact and Organisation.
My code behind looks like this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
SqlDataAdapter1.Fill(DsLPSppContact1)
DataGrid1.DataBind()
End If
End Sub
'Paging
Private Sub DataGrid1_PageIndexChanged(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
SqlDataAdapter1.Fill(DsLPSppContact1)
DataGrid1.DataBind()
End Sub
'Sorting
Private Sub DataGrid1_SortCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) _
Handles DataGrid1.SortCommand
Dim dt As New DataTable()
Dim dataview1 As New DataView(dt)
dataview1.Sort = e.SortExpression
DataGrid1.DataBind()
End Sub
But if I try to sort on, for example "Contact" I keep getting the error: System.IndexOutOfRangeException: Cannot find column Contact
Please can anyone help?
Cheers
Barleywine
The Column names I want to sort on are: Species, Contact and Organisation.
My code behind looks like this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
SqlDataAdapter1.Fill(DsLPSppContact1)
DataGrid1.DataBind()
End If
End Sub
'Paging
Private Sub DataGrid1_PageIndexChanged(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
SqlDataAdapter1.Fill(DsLPSppContact1)
DataGrid1.DataBind()
End Sub
'Sorting
Private Sub DataGrid1_SortCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) _
Handles DataGrid1.SortCommand
Dim dt As New DataTable()
Dim dataview1 As New DataView(dt)
dataview1.Sort = e.SortExpression
DataGrid1.DataBind()
End Sub
But if I try to sort on, for example "Contact" I keep getting the error: System.IndexOutOfRangeException: Cannot find column Contact
Please can anyone help?
Cheers
Barleywine