Error When Sorting

S

Steve Bishop

I'm using the data grid with an ODBC database. I get an error when
clicking on the sorting. Either the page can't be displayed or I get the
error:
"The viewstate is invalid for this page and might be corrupted." Help
appreciated. Thanks.

<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="Microsoft.Data.ODBC" %>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="dgAR1" runat="server" AllowSorting="True"
OnSortCommand="SortColumn"/>

</form>
</body>
</html>

<script runat="server">
Public strViewString As String

Sub SetData()

Dim cn as OdbcConnection
cn = New OdbcConnection("dsn=SOTAMAS90AUTO;uid=sys;pwd=Rush;")
Dim mystring As String = "Select Division, CustomerNumber,
CustomerName, AddressLine1 FROM AR1_CustomerMaster"

Dim ObjAdapter As New OdbcDataAdapter(mystring, cn)

Dim ObjDataSet As New DataSet()

ObjAdapter.Fill(objDataSet, "dtAR1")

Dim dtAR1 As DataTable = objDataSet.Tables("dtAR1")

Dim dvView As New DataView(dtAR1)
dvView.Sort = strViewString


dgAR1.DataSource = dvView
dgAR1.DataBind()
End Sub

Sub Page_Load(Source As Object, E As EventArgs)
If Not Page.IsPostBack Then
strViewString = "CustomerNumber"
SetData()
End If
End Sub

Sub SortColumn(Source As Object, E As DataGridSortCommandEventArgs)
If E.SortExpression = "Division" Then
strViewString = "Division, CustomerNumber"
Else
strViewString = E.SortExpression
End If
SetData()

End Sub

</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top