DataGrid Sorting Problems

S

Steve Bishop

I get an error when trying to click on the sorting links in the header.
Would anyone know why I would receive this error? Unfortunately, I need
to work with ODBC connections. Help appreciated. Error is: "The
viewstate is invalid for this page and might be corrupted."

<%@ 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>
 
H

Homer J. Simpson

Steve,

Have you tried to add this compilation directive at the very beginning of
your page ?

<%@ Page Language="VB" EnableViewState="True" %>

Hope this helps,
Regards,
Jean-Philippe
 
S

Steve Bishop

Thanks, but I found out what it was. Web Matrix comes with it's own Web
Server or you have a choice of an IIS virtual directory. It runs fine in
the virtual directory. Guess I wont be using it's built in server
anymore!

Thanks
 

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,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top