10 Replies - 3126 Views - Last Post: 24 June 2010 - 07:21 PM Rate Topic: -----

#1 Needanswer   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 61
  • Joined: 27-January 10

Error on the gridview (vwd 2008 express with access)

Posted 21 June 2010 - 07:32 PM

 </asp:TemplateField>
                <asp:TemplateField HeaderText="System Manager" SortExpression="sysaccount">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("sysaccount") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("sysaccount") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Password" SortExpression="syspw">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("syspw") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("syspw") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Log" SortExpression="log">
                    <EditItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("log") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("log") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>





I changed the code FOR SORTING, TOOK OUT THE "NOT ISPOSTBACK",
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'If Not IsPostBack Then
            BindGridView()
        'End If
    End Sub



the sorting is working, but, I got the error - Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation. WHEN I CLICK THE UPDATE, DELETE.

The rests;
Private Sub BindGridView()
        ' Code to retrieve records from database and fill it in a DataTable and Bind it to GridView
        Dim dt As DataTable = New DataTable()
        Dim conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\user\Desktop\honor.mdb")
        Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Sysdep", conn)
        conn.Open()
        da.Fill(dt)
        da.Dispose()
        conn.Close()

        GridView1.DataSource = dt
        GridView1.DataBind()
    End Sub



Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
        Dim dtSortTable As DataTable = TryCast(GridView1.DataSource, DataTable)

        If dtSortTable IsNot Nothing Then
            Dim dvSortedView As New DataView(dtSortTable)
            dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection)

            GridView1.DataSource = dvSortedView
            GridView1.DataBind()
            'BindGridView()
        End If
    End Sub
    Private Function getSortDirectionString(ByVal sortDireciton As SortDirection) As String
        Dim newSortDirection As String = [String].Empty
        If sortDireciton = SortDirection.Ascending Then
            newSortDirection = "ASC"
        Else
            newSortDirection = "DESC"
        End If

        Return newSortDirection
    End Function



How to fix? Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Error on the gridview (vwd 2008 express with access)

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Error on the gridview (vwd 2008 express with access)

Posted 21 June 2010 - 07:50 PM

One thing to try is calling your bind method in the PreRender event instead of the load, like this

protected void Page_PreRender(object o, System.EventArgs e)
{
     BindGridView();
}


Was This Post Helpful? 0
  • +
  • -

#3 Frinavale   User is offline

  • D.I.C Addict
  • member icon

Reputation: 205
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: Error on the gridview (vwd 2008 express with access)

Posted 22 June 2010 - 08:52 AM

I tried to reproduce what you are doing.
I cannot retrieve the GridView1.DataSource in the GridView1's Sorting method.
It is always nothing.

I don't see how you can get the error that you are receiving.
You typically get this error if you are dynamically adding controls to your GridView somehow... you get this error when these dynamic controls don't match up with the what the server is expecting. I've seen it many many times.

But in the code you posted you aren't dynamically creating controls.
Maybe you have some Javascript that is doing something either to modify the controls GridView when it exists in the browser...or you have some Javascript that is submitting the page using a control in the GridView that "doesn't exist" according to ASP.NET

Your code, as you have posted it, does not contain anything that will cause the error that you have posted. The cod you have posted, also, will not work.

I created some test code based on your code.
Here is the my GridView markup:
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowSorting="true">
    <Columns>
        <asp:TemplateField HeaderText="System Manager" SortExpression="sysaccount">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("sysaccount") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("sysaccount") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Password" SortExpression="syspw">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("syspw") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Bind("syspw") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Log" SortExpression="log">
            <EditItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Eval("log") %>'></asp:Label>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label4" runat="server" Text='<%# Bind("log") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>


Here is the method that sorts the GridView:
Private Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
        'Retrieving the DataView (the datasource for GridView1) from session so that we'
        'do not have to recreate it by making a call to the database '
        Dim dv As DataView = CType(Session("GridView1sDataSource"), DataView)
        'Checking to make sure we were able to retrieve the data source from session before using the datasource '
        If dv IsNot Nothing Then

            'Determining which way to sort the datasource'
            Dim sortDirection As String = "DESC" 'by default, sorting the column in decending order'
            'Checking to see which direction the column was previously sort as'
            If (ViewState(e.SortExpression) IsNot Nothing AndAlso String.Compare(ViewState(e.SortExpression), "DESC") = 0) Then
                'If the column was previously sorted, and the column was sorted in a Decending direction'
                'specifying that the column should be sorted in an Ascending direction'
                sortDirection = "ASC"
            End If
            'Sorting the column based on the direction specified in the sortDirection string'
            dv.Sort = e.SortExpression + " " + sortDirection
            'Saving the sort direction for the column so that we can check its sort direction next time'
            ViewState(e.SortExpression) = sortDirection
            'Saving the datasource'
            Session("GridView1sDataSource") = dv
            'Setting the GridView1.DataSource property to the sorted DataView'
            GridView1.DataSource = dv
        End If
End Sub


And here is my Page's PreRender event code:
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        If IsPostBack = False Then
            'If it is the first time the page is loaded...'
            'creating a new datasource for the GridView'

            '(Here you should be retrieving the data source from your database'
            ' but I do not have a database so I am creating a table)'
            Dim dt As New DataTable
            dt.Columns.Add("sysaccount", GetType(Integer))
            dt.Columns.Add("syspw", GetType(String))
            dt.Columns.Add("log", GetType(String))

            For i As Integer = 0 To 10
                Dim dr As DataRow = dt.NewRow
                dr("sysaccount") = i
                dr("syspw") = i.ToString + " syspw"
                dr("log") = i.ToString + " log"
                dt.Rows.Add(dr)
            Next

            'Creating a DataView based on the table I just generated'
            Dim dv As New DataView(dt)
            'Setting the GridView1.DataSource to the DataView'
            GridView1.DataSource = dv
            'Saving the DataView in Session so that I do not have to'
            'recreate the source again next page request...I can just'
            'retrieve it from session'
            Session("GridView1sDataSource") = dv
        Else
            'If it is not the first time the page is loaded...'
            'And GridView1.DataSource has not been previously set...'
            'Retrieving the datasource (DataView) from Session and setting the DataSource'
            If GridView1.DataSource Is Nothing Then
                Dim dv As DataView = CType(Session("GridView1sDataSource"), DataView)
                GridView1.DataSource = dv
            End If
        End If
        'Binding the GridView to the Data Source'
        GridView1.DataBind()

End Sub


I did not encounter the error that you mentioned.

-Frinny

This post has been edited by Frinavale: 22 June 2010 - 08:59 AM

Was This Post Helpful? 0
  • +
  • -

#4 Guest_needanswer*


Reputation:

Re: Error on the gridview (vwd 2008 express with access)

Posted 22 June 2010 - 06:27 PM

View PostPsychoCoder, on 21 June 2010 - 06:50 PM, said:

One thing to try is calling your bind method in the PreRender event instead of the load, like this

protected void Page_PreRender(object o, System.EventArgs e)
{
     BindGridView();
}



I don't see the errors when I clicked the update, cancel, edit, delete, but sorting is not working.
Was This Post Helpful? 0

#5 Guest_needanswer*


Reputation:

Re: Error on the gridview (vwd 2008 express with access)

Posted 22 June 2010 - 06:38 PM

View PostFrinavale, on 22 June 2010 - 07:52 AM, said:

I tried to reproduce what you are doing.
I cannot retrieve the GridView1.DataSource in the GridView1's Sorting method.
It is always nothing.

I don't see how you can get the error that you are receiving.
You typically get this error if you are dynamically adding controls to your GridView somehow... you get this error when these dynamic controls don't match up with the what the server is expecting. I've seen it many many times.

But in the code you posted you aren't dynamically creating controls.
Maybe you have some Javascript that is doing something either to modify the controls GridView when it exists in the browser...or you have some Javascript that is submitting the page using a control in the GridView that "doesn't exist" according to ASP.NET

Your code, as you have posted it, does not contain anything that will cause the error that you have posted. The cod you have posted, also, will not work.

I created some test code based on your code.
Here is the my GridView markup:
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowSorting="true">
    <Columns>
        <asp:TemplateField HeaderText="System Manager" SortExpression="sysaccount">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("sysaccount") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("sysaccount") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Password" SortExpression="syspw">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("syspw") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Bind("syspw") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Log" SortExpression="log">
            <EditItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Eval("log") %>'></asp:Label>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label4" runat="server" Text='<%# Bind("log") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>


Here is the method that sorts the GridView:
Private Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
        'Retrieving the DataView (the datasource for GridView1) from session so that we'
        'do not have to recreate it by making a call to the database '
        Dim dv As DataView = CType(Session("GridView1sDataSource"), DataView)
        'Checking to make sure we were able to retrieve the data source from session before using the datasource '
        If dv IsNot Nothing Then

            'Determining which way to sort the datasource'
            Dim sortDirection As String = "DESC" 'by default, sorting the column in decending order'
            'Checking to see which direction the column was previously sort as'
            If (ViewState(e.SortExpression) IsNot Nothing AndAlso String.Compare(ViewState(e.SortExpression), "DESC") = 0) Then
                'If the column was previously sorted, and the column was sorted in a Decending direction'
                'specifying that the column should be sorted in an Ascending direction'
                sortDirection = "ASC"
            End If
            'Sorting the column based on the direction specified in the sortDirection string'
            dv.Sort = e.SortExpression + " " + sortDirection
            'Saving the sort direction for the column so that we can check its sort direction next time'
            ViewState(e.SortExpression) = sortDirection
            'Saving the datasource'
            Session("GridView1sDataSource") = dv
            'Setting the GridView1.DataSource property to the sorted DataView'
            GridView1.DataSource = dv
        End If
End Sub


And here is my Page's PreRender event code:
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        If IsPostBack = False Then
            'If it is the first time the page is loaded...'
            'creating a new datasource for the GridView'

            '(Here you should be retrieving the data source from your database'
            ' but I do not have a database so I am creating a table)'
            Dim dt As New DataTable
            dt.Columns.Add("sysaccount", GetType(Integer))
            dt.Columns.Add("syspw", GetType(String))
            dt.Columns.Add("log", GetType(String))

            For i As Integer = 0 To 10
                Dim dr As DataRow = dt.NewRow
                dr("sysaccount") = i
                dr("syspw") = i.ToString + " syspw"
                dr("log") = i.ToString + " log"
                dt.Rows.Add(dr)
            Next

            'Creating a DataView based on the table I just generated'
            Dim dv As New DataView(dt)
            'Setting the GridView1.DataSource to the DataView'
            GridView1.DataSource = dv
            'Saving the DataView in Session so that I do not have to'
            'recreate the source again next page request...I can just'
            'retrieve it from session'
            Session("GridView1sDataSource") = dv
        Else
            'If it is not the first time the page is loaded...'
            'And GridView1.DataSource has not been previously set...'
            'Retrieving the datasource (DataView) from Session and setting the DataSource'
            If GridView1.DataSource Is Nothing Then
                Dim dv As DataView = CType(Session("GridView1sDataSource"), DataView)
                GridView1.DataSource = dv
            End If
        End If
        'Binding the GridView to the Data Source'
        GridView1.DataBind()

End Sub


I did not encounter the error that you mentioned.

-Frinny


Actually all buttons are working on the first time, except the sorting. After done the sorting, the sorting was working, but got errors on all buttons as mentioned on the above. I did use your sample, it is not working,errors. (sysaccount - name, syspw - password, log - time log)
Was This Post Helpful? 0

#6 Frinavale   User is offline

  • D.I.C Addict
  • member icon

Reputation: 205
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: Error on the gridview (vwd 2008 express with access)

Posted 22 June 2010 - 08:51 PM

I hope you are aware that my example is not going to work with your data source...it can't because I have no idea what's in your data table... If you create a new page and paste my code in as is, it will work. (I know it will because I used it)

Now, back to the code you posted.
There are no buttons anywhere in this code...


-Frinny
Was This Post Helpful? 0
  • +
  • -

#7 Needanswer   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 61
  • Joined: 27-January 10

Re: Error on the gridview (vwd 2008 express with access)

Posted 22 June 2010 - 11:42 PM

View PostFrinavale, on 22 June 2010 - 07:51 PM, said:

I hope you are aware that my example is not going to work with your data source...it can't because I have no idea what's in your data table... If you create a new page and paste my code in as is, it will work. (I know it will because I used it)

Now, back to the code you posted.
There are no buttons anywhere in this code...


-Frinny


Frinny,

This is on the front; all buttons are working, except the sorting on the first time. And now sorting is working - TOOK OUT THE "NOT ISPOSTBACK", BUT, all buttons got errors as on the above, this is on the vwd 2008 express, I don't think it will be so complicated, anyone knows how to fix it? Thanks.


 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" BackColor="White" 
        BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
        DataKeyNames="id"  GridLines="Vertical" Width="739px"  >
        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
        <Columns>
            <asp:TemplateField ShowHeader="False" HeaderText="Edit">
                <EditItemTemplate>
                    <asp:Button ID="Button1" runat="server" CausesValidation="True" 
                        CommandName="Update" Text="Update" />
                    &nbsp;<asp:Button ID="Button2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" Text="Cancel" />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Button ID="Button2" runat="server" CausesValidation="False" 
                        CommandName="Select" Text="Select" />
                     &nbsp;<asp:Button ID="Button1" runat="server" CausesValidation="False" 
                        CommandName="Edit" Text="Edit" />
                   
                    &nbsp;<asp:Button ID="Button3" runat="server" CausesValidation="False" 
                        CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure to Delete the record?')"/>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="id" InsertVisible="False" SortExpression="id" 
                Visible="False">
                <EditItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("id") %>'></asp:Label>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("id") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="System Manager" SortExpression="sysaccount">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("sysaccount") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("sysaccount") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Password" SortExpression="syspw">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("syspw") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("syspw") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Log/Time" SortExpression="log">
                <EditItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Eval("log") %>'></asp:Label>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("log") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="#DCDCDC" />
    </asp:GridView>
    <br />
    <asp:Label ID="Label2" runat="server" 
        style="font-family: Times New Roman; font-size: large; font-weight: 700" Text="System Manager"></asp:Label>
&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <br />
    <br />
    <asp:Label ID="Label3" runat="server" Text="Password"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
&nbsp;<br />
    <br />
    <br />
    <asp:Button ID="Button4" runat="server" 
        style="font-family: Time New Roman; font-size: large; font-weight: 700" Text="Add" />
&nbsp;<asp:Button ID="Button5" runat="server" 
        style="font-family: Time New Roman; font-size: large; font-weight: 700" Text="Cancel" />
&nbsp;<asp:Button ID="Button6" runat="server" 
        style="font-family: Time New Roman; font-size: large; font-weight: 700" Text="Save" />
    </form>



Was This Post Helpful? 0
  • +
  • -

#8 Frinavale   User is offline

  • D.I.C Addict
  • member icon

Reputation: 205
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: Error on the gridview (vwd 2008 express with access)

Posted 23 June 2010 - 08:17 AM

I'm not sure what is wrong with your code but when I copied/pasted it I encountered the same problem.
Here is a cleaned up, working, test version that you can use.
I suggest that you put this code in new aspx page because encountered the problem even when I created a new GridView on the same page as your mark up. There is something not right in your markup that is causing this to happen.

Anyways, here's the working GridView asp markup:
        <asp:GridView ID="GridView1" runat="server" 
            BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" Width="739px"  
            DataKeyNames="id"  
            AutoGenerateColumns="false" 
            EnableViewState="true" 
            AllowPaging="true"
            AllowSorting="True" 
            OnRowCommand="GridView1_RowCommand" 
            OnRowEditing="GridView1_RowEditing"
            OnRowDeleting="GridView1_RowDeleting" 
            onselectedIndexChanging="GridView1_SelectedIndexChanging"
            OnRowUpdating="GridView1_RowUpdating" 
            OnRowCancelingEdit="GridView1_RowCancelingEdit">
            <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
            <Columns>
                <asp:TemplateField HeaderText="Operations">
                    <ItemTemplate>
                        <asp:Button ID="selectButton" runat="server" CommandName="Select" Text="Select">
                        </asp:Button>
                        <asp:Button ID="editButton" runat="server" CommandName="Edit" Text="Edit">
                        </asp:Button>
                        <asp:Button ID="deleteButton" runat="server" CommandName="Delete" Text="Delete"
                            OnClientClick="return confirm('Are you sure to Delete the record?')"></asp:Button>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:Button ID="updateButton" runat="server" CommandName="Update" Text="Update">
                        </asp:Button>
                        <asp:Button ID="cancelUpdateButton" runat="server" CommandName="Cancel" Text="Cancel"></asp:Button>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="id" SortExpression="id" Visible="False">
                    <EditItemTemplate>
                        <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="idLabel" runat="server" Text='<%# Bind("id") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="System Manager" SortExpression="sysaccount">
                    <EditItemTemplate>
                        <asp:TextBox ID="sysAccountTextBox" runat="server" Text='<%# Bind("sysaccount") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="sysAccountLabel" runat="server" Text='<%# Bind("sysaccount") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Password" SortExpression="syspw">
                    <EditItemTemplate>
                        <asp:TextBox ID="passwordTextBox" runat="server" Text='<%# Bind("syspw") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="passwordLabel" runat="server" Text='<%# Bind("syspw") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Log/Time" SortExpression="log">
                    <EditItemTemplate>
                        <asp:Label ID="logTextBox" runat="server" Text='<%# Eval("log") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="logLabel" runat="server" Text='<%# Bind("log") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="#DCDCDC" />
        </asp:GridView>


(Notice how I gave the control Meaningful Names! It is always a good idea to do this so that you know what is what)

Here is the working VB.NET code (it doesn't do much....but it works):
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
    Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        If IsPostBack = False Then
            Dim dt As New DataTable
            dt.Columns.Add("id", GetType(Integer))
            dt.Columns.Add("sysaccount", GetType(Integer))
            dt.Columns.Add("syspw", GetType(String))
            dt.Columns.Add("log", GetType(String))

            For i As Integer = 0 To 10
                Dim dr As DataRow = dt.NewRow
                dr("id") = i
                dr("sysaccount") = i * 5
                dr("syspw") = i.ToString + " syspw"
                dr("log") = i.ToString + " log"
                dt.Rows.Add(dr)
            Next
            Dim dv As New DataView(dt)
            GridView1.DataSource = dv
            Session("GridView1sDataSource") = dv
        Else
            If GridView1.DataSource Is Nothing Then
                Dim dv As DataView = CType(Session("GridView1sDataSource"), DataView)
                GridView1.DataSource = dv
            End If
        End If
        GridView1.DataBind()
    End Sub

    Private Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
        GridView1.SelectedIndex = -1
        GridView1.EditIndex = -1
        Dim dv As DataView = CType(Session("GridView1sDataSource"), DataView)
        If dv IsNot Nothing Then
            Dim sortDirection As String = "DESC"
            If (ViewState(e.SortExpression) IsNot Nothing AndAlso String.Compare(ViewState(e.SortExpression), "DESC") = 0) Then
                sortDirection = "ASC"
            End If
            dv.Sort = e.SortExpression + " " + sortDirection
            ViewState(e.SortExpression) = sortDirection
            Session("GridView1sDataSource") = dv
            GridView1.DataSource = dv
        End If
    End Sub
    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
    End Sub

    Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs)
    End Sub

    Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs)
        GridView1.EditIndex = e.NewEditIndex
    End Sub

    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
        GridView1.EditIndex = -1
    End Sub

    Protected Sub GridView1_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs)
        GridView1.SelectedIndex = e.NewSelectedIndex
    End Sub

    Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs)
        GridView1.EditIndex = -1
    End Sub


Like I said, try this code out in a new aspx page.
Feel free to modify it for your needs...but I recommend you test everything each time you make a change.

If you encounter the problem again after changing something then you know what's causing the problem....please post back here if you do.

-Frinny

This post has been edited by Frinavale: 23 June 2010 - 08:21 AM

Was This Post Helpful? 0
  • +
  • -

#9 Needanswer   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 61
  • Joined: 27-January 10

Re: Error on the gridview (vwd 2008 express with access)

Posted 23 June 2010 - 07:34 PM

View PostFrinavale, on 23 June 2010 - 07:17 AM, said:

I'm not sure what is wrong with your code but when I copied/pasted it I encountered the same problem.
Here is a cleaned up, working, test version that you can use.
I suggest that you put this code in new aspx page because encountered the problem even when I created a new GridView on the same page as your mark up. There is something not right in your markup that is causing this to happen.

Anyways, here's the working GridView asp markup:
        <asp:GridView ID="GridView1" runat="server" 
            BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" Width="739px"  
            DataKeyNames="id"  
            AutoGenerateColumns="false" 
            EnableViewState="true" 
            AllowPaging="true"
            AllowSorting="True" 
            OnRowCommand="GridView1_RowCommand" 
            OnRowEditing="GridView1_RowEditing"
            OnRowDeleting="GridView1_RowDeleting" 
            onselectedIndexChanging="GridView1_SelectedIndexChanging"
            OnRowUpdating="GridView1_RowUpdating" 
            OnRowCancelingEdit="GridView1_RowCancelingEdit">
            <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
            <Columns>
                <asp:TemplateField HeaderText="Operations">
                    <ItemTemplate>
                        <asp:Button ID="selectButton" runat="server" CommandName="Select" Text="Select">
                        </asp:Button>
                        <asp:Button ID="editButton" runat="server" CommandName="Edit" Text="Edit">
                        </asp:Button>
                        <asp:Button ID="deleteButton" runat="server" CommandName="Delete" Text="Delete"
                            OnClientClick="return confirm('Are you sure to Delete the record?')"></asp:Button>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:Button ID="updateButton" runat="server" CommandName="Update" Text="Update">
                        </asp:Button>
                        <asp:Button ID="cancelUpdateButton" runat="server" CommandName="Cancel" Text="Cancel"></asp:Button>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="id" SortExpression="id" Visible="False">
                    <EditItemTemplate>
                        <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="idLabel" runat="server" Text='<%# Bind("id") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="System Manager" SortExpression="sysaccount">
                    <EditItemTemplate>
                        <asp:TextBox ID="sysAccountTextBox" runat="server" Text='<%# Bind("sysaccount") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="sysAccountLabel" runat="server" Text='<%# Bind("sysaccount") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Password" SortExpression="syspw">
                    <EditItemTemplate>
                        <asp:TextBox ID="passwordTextBox" runat="server" Text='<%# Bind("syspw") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="passwordLabel" runat="server" Text='<%# Bind("syspw") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Log/Time" SortExpression="log">
                    <EditItemTemplate>
                        <asp:Label ID="logTextBox" runat="server" Text='<%# Eval("log") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="logLabel" runat="server" Text='<%# Bind("log") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="#DCDCDC" />
        </asp:GridView>


(Notice how I gave the control Meaningful Names! It is always a good idea to do this so that you know what is what)

Here is the working VB.NET code (it doesn't do much....but it works):
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
    Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        If IsPostBack = False Then
            Dim dt As New DataTable
            dt.Columns.Add("id", GetType(Integer))
            dt.Columns.Add("sysaccount", GetType(Integer))
            dt.Columns.Add("syspw", GetType(String))
            dt.Columns.Add("log", GetType(String))

            For i As Integer = 0 To 10
                Dim dr As DataRow = dt.NewRow
                dr("id") = i
                dr("sysaccount") = i * 5
                dr("syspw") = i.ToString + " syspw"
                dr("log") = i.ToString + " log"
                dt.Rows.Add(dr)
            Next
            Dim dv As New DataView(dt)
            GridView1.DataSource = dv
            Session("GridView1sDataSource") = dv
        Else
            If GridView1.DataSource Is Nothing Then
                Dim dv As DataView = CType(Session("GridView1sDataSource"), DataView)
                GridView1.DataSource = dv
            End If
        End If
        GridView1.DataBind()
    End Sub

    Private Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
        GridView1.SelectedIndex = -1
        GridView1.EditIndex = -1
        Dim dv As DataView = CType(Session("GridView1sDataSource"), DataView)
        If dv IsNot Nothing Then
            Dim sortDirection As String = "DESC"
            If (ViewState(e.SortExpression) IsNot Nothing AndAlso String.Compare(ViewState(e.SortExpression), "DESC") = 0) Then
                sortDirection = "ASC"
            End If
            dv.Sort = e.SortExpression + " " + sortDirection
            ViewState(e.SortExpression) = sortDirection
            Session("GridView1sDataSource") = dv
            GridView1.DataSource = dv
        End If
    End Sub
    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
    End Sub

    Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs)
    End Sub

    Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs)
        GridView1.EditIndex = e.NewEditIndex
    End Sub

    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
        GridView1.EditIndex = -1
    End Sub

    Protected Sub GridView1_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs)
        GridView1.SelectedIndex = e.NewSelectedIndex
    End Sub

    Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs)
        GridView1.EditIndex = -1
    End Sub


Like I said, try this code out in a new aspx page.
Feel free to modify it for your needs...but I recommend you test everything each time you make a change.

If you encounter the problem again after changing something then you know what's causing the problem....please post back here if you do.

-Frinny


Couldn't connect with Access? I did your sample.

Here is my original code connecting with Access.
Imports System.Data
Imports System.Data.OleDb
Partial Class SystemManager
    Inherits System.Web.UI.Page
    Dim con1 As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\user\Desktop\honor.mdb")
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'If Not IsPostBack Then
        BindGridView()
        'End If

    End Sub

 Private Sub BindGridView()
        ' Code to retrieve records from database and fill it in a DataTable and Bind it to GridView
        Dim dt As DataTable = New DataTable()
        Dim conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\user\Desktop\honor.mdb")
        Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Sysdep", conn)
        conn.Open()
        da.Fill(dt)
        da.Dispose()
        conn.Close()

        GridView1.DataSource = dt
        GridView1.DataBind()
    End Sub

Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
        GridView1.EditIndex = e.NewEditIndex
        BindGridView()
    End Sub
    Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
        GridView1.EditIndex = -1
        BindGridView()
    End Sub
 Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex
        BindGridView()
    End Sub
    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim sqlupdate As String

        sqlupdate = "UPDATE sysdep SET sysaccount= @sysaccount, syspw= @syspw WHERE id= @id"

        Dim cmd1 As New OleDbCommand(sqlupdate, con1)


        cmd1.Parameters.Add(New OleDbParameter("@sysaccount", CType(GridView1.Rows(e.RowIndex).FindControl("TextBox1"), TextBox).Text.ToString()))
        cmd1.Parameters.Add(New OleDbParameter("@syspw", CType(GridView1.Rows(e.RowIndex).FindControl("TextBox2"), TextBox).Text.ToString()))
        cmd1.Parameters.Add(New OleDbParameter("@id", GridView1.DataKeys(e.RowIndex).Value.ToString()))



        Try
            con1.Open()
            cmd1.ExecuteNonQuery()
        Catch ex As OleDbException
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web")
        Catch ex As InvalidOperationException
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web")
        End Try

        con1.Close()


        GridView1.EditIndex = -1
        BindGridView()


    End Sub

    Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting

        Dim sqldelete As String

        sqldelete = "DELETE FROM sysdep WHERE id=" & GridView1.DataKeys(e.RowIndex).Value.ToString()

        Dim cmd2 As New OleDbCommand(sqldelete, con1)

        Try
            con1.Open()
            cmd2.ExecuteNonQuery()
        Catch ex As OleDbException
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web")
        Catch ex As InvalidOperationException
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web")
        End Try

        con1.Close()
        BindGridView()


    End Sub

    Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
        Dim dtSortTable As DataTable = TryCast(GridView1.DataSource, DataTable)

        If dtSortTable IsNot Nothing Then
            Dim dvSortedView As New DataView(dtSortTable)
            dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection)

            GridView1.DataSource = dvSortedView
            GridView1.DataBind()
        End If
    End Sub
    Private Function getSortDirectionString(ByVal sortDireciton As SortDirection) As String
        Dim newSortDirection As String = [String].Empty
        If sortDireciton = SortDirection.Ascending Then
            newSortDirection = "ASC"
        Else
            newSortDirection = "DESC"
        End If

        Return newSortDirection

    End Function
   
    Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click

        Dim sqlinsert As String

        sqlinsert = "INSERT INTO sysdep (sysaccount,syspw)" & _
          "VALUES(@sysaccount, @syspw)"

        Dim cmd As New OleDbCommand(sqlinsert, con1)

        cmd.Parameters.Add(New OleDbParameter("@sysaccount", TextBox1.Text))
        cmd.Parameters.Add(New OleDbParameter("@syspw", TextBox2.Text))

        Try
            con1.Open()
            cmd.ExecuteNonQuery()
        Catch ex As OleDbException
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web")
        Catch ex As InvalidOperationException
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web")
        End Try
        con1.Close()

        BindGridView()

    End Sub
    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox1.Text = ""
        TextBox1.Focus()
        TextBox1.Text = ""
    End Sub
    Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
    End Sub

End Class


Was This Post Helpful? 0
  • +
  • -

#10 Frinavale   User is offline

  • D.I.C Addict
  • member icon

Reputation: 205
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: Error on the gridview (vwd 2008 express with access)

Posted 24 June 2010 - 06:12 AM

Apparently you are trying to solve 2 problems at the same time.

The first problem had to do with the "Invalid postback or callback argument. Event validation..." error.

Did my code fix that problem for you?


The second problem you're having is retrieving data from the database..
Did you read the comments in my Page PreRender code:
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        If IsPostBack = False Then
            'If it is the first time the page is loaded...'
            'creating a new datasource for the GridView'

            '(Here you should be retrieving the data source from your database'
            ' but I do not have a database so I am creating a table)'
            Dim dt As New DataTable
            dt.Columns.Add("sysaccount", GetType(Integer))
            dt.Columns.Add("syspw", GetType(String))
            dt.Columns.Add("log", GetType(String))

            For i As Integer = 0 To 10
                Dim dr As DataRow = dt.NewRow
                dr("sysaccount") = i
                dr("syspw") = i.ToString + " syspw"
                dr("log") = i.ToString + " log"
                dt.Rows.Add(dr)
            Next

            'Creating a DataView based on the table I just generated'
            Dim dv As New DataView(dt)
            'Setting the GridView1.DataSource to the DataView'
            GridView1.DataSource = dv
            'Saving the DataView in Session so that I do not have to'
            'recreate the source again next page request...I can just'
            'retrieve it from session'
            Session("GridView1sDataSource") = dv
        Else
            'If it is not the first time the page is loaded...'
            'And GridView1.DataSource has not been previously set...'
            'Retrieving the datasource (DataView) from Session and setting the DataSource'
            If GridView1.DataSource Is Nothing Then
                Dim dv As DataView = CType(Session("GridView1sDataSource"), DataView)
                GridView1.DataSource = dv
            End If
        End If
        'Binding the GridView to the Data Source'
        GridView1.DataBind()

End Sub


See where I'm populating a table?
That is where you want to retrieve the data from the database.
After you've retrieved the data I recommend that you create a DataView based off of the table data you retrieved (like I am doing in code) and store that DataView in Session or Cache or something so that you don't have to make too many, unnecessary calls to the database.

I recommend creating a DataView because DataViews support things like (sorting and more).

-Frinny
Was This Post Helpful? 0
  • +
  • -

#11 Guest_needanswer*


Reputation:

Re: Error on the gridview (vwd 2008 express with access)

Posted 24 June 2010 - 07:21 PM

View PostFrinavale, on 24 June 2010 - 05:12 AM, said:

Apparently you are trying to solve 2 problems at the same time.

The first problem had to do with the "Invalid postback or callback argument. Event validation..." error.

Did my code fix that problem for you?


The second problem you're having is retrieving data from the database..
Did you read the comments in my Page PreRender code:
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        If IsPostBack = False Then
            'If it is the first time the page is loaded...'
            'creating a new datasource for the GridView'

            '(Here you should be retrieving the data source from your database'
            ' but I do not have a database so I am creating a table)'
            Dim dt As New DataTable
            dt.Columns.Add("sysaccount", GetType(Integer))
            dt.Columns.Add("syspw", GetType(String))
            dt.Columns.Add("log", GetType(String))

            For i As Integer = 0 To 10
                Dim dr As DataRow = dt.NewRow
                dr("sysaccount") = i
                dr("syspw") = i.ToString + " syspw"
                dr("log") = i.ToString + " log"
                dt.Rows.Add(dr)
            Next

            'Creating a DataView based on the table I just generated'
            Dim dv As New DataView(dt)
            'Setting the GridView1.DataSource to the DataView'
            GridView1.DataSource = dv
            'Saving the DataView in Session so that I do not have to'
            'recreate the source again next page request...I can just'
            'retrieve it from session'
            Session("GridView1sDataSource") = dv
        Else
            'If it is not the first time the page is loaded...'
            'And GridView1.DataSource has not been previously set...'
            'Retrieving the datasource (DataView) from Session and setting the DataSource'
            If GridView1.DataSource Is Nothing Then
                Dim dv As DataView = CType(Session("GridView1sDataSource"), DataView)
                GridView1.DataSource = dv
            End If
        End If
        'Binding the GridView to the Data Source'
        GridView1.DataBind()

End Sub


See where I'm populating a table?
That is where you want to retrieve the data from the database.
After you've retrieved the data I recommend that you create a DataView based off of the table data you retrieved (like I am doing in code) and store that DataView in Session or Cache or something so that you don't have to make too many, unnecessary calls to the database.

I recommend creating a DataView because DataViews support things like (sorting and more).

-Frinny


Yes, when I did your sample, the first problem was solved, but the sorting and I didn't see the connection with Access (I already have some database in), I only saw bunch 1...10 on the rows, sysaccount .....on the rows, etc.
Was This Post Helpful? 0

Page 1 of 1