Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 1st, 2004, 03:31 PM
Registered User
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datagrid not showing modifications

Hi there,

I having a bit (understatement) of a problem here with datagrids. If a record is deleted or amended the new values are not diplayed. However, if i click the refresh button on the browser, the new values are displayed. Im rebinding the data each time the database is modified, so I cant understand why the updates are not being displayed until the page is reloaded.

Any ideas? Heres the code I'm using.


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
            GetPersonalInfo()
            BindDataVehicleInfo()
        End If
    End Sub


    Sub BindDataVehicleInfo()
        Dim intCustNo As Integer = Request.Cookies("GCSCommerce_CustNo").Value
        Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\GCSwebsite.mdb") & ";"
        Dim MySQL As String = "SELECT RegNo, Make, Model, CarYear, EngineSize, FuelType FROM Vehicles " & _
        "WHERE (((CustNo)=" & intCustNo & "));"
        Dim MyConn As New OleDbConnection(strConn)
        Dim objDR As OleDbDataReader
        Dim Cmd As New OleDbCommand(MySQL, MyConn)

        MyConn.Open()
        objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.Clos eConnection)

        If Not objDR.Read() Then
            objDR.Close()
            MyConn.Open()
            Cmd.ExecuteNonQuery()
            lblNoVehicles.Text = "There are no vehicles associated with you account. Please add your vehicle details by clicking"
            HyperLink1.Visible = True
            HyperLink2.Visible = False
            dgVehicleInfo.Visible = False
        Else
            objDR.Close()
            MyConn.Open()
            'Set the datagrid's datasource to the datareader and databind
            dgVehicleInfo.DataSource = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
            dgVehicleInfo.DataBind()
        End If
    End Sub

    Sub dgVehicleInfo_Edit(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
        dgVehicleInfo.EditItemIndex = e.Item.ItemIndex
        BindDataVehicleInfo() 'Rebuild datagrid to display new info
    End Sub

    Sub dgVehicleInfo_Cancel(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
        dgVehicleInfo.EditItemIndex = -1
        BindDataVehicleInfo()
    End Sub

    Sub dgVehicleInfo_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
        'Read in the values of the updated row
        Dim strRegNo As String = dgVehicleInfo.DataKeys(e.Item.ItemIndex)
        Dim strMake As String = CType(e.Item.FindControl("txtMake"), TextBox).Text
        Dim strModel As String = CType(e.Item.FindControl("txtModel"), TextBox).Text
        Dim strCarYear As String = CType(e.Item.FindControl("txtCarYear"), TextBox).Text
        Dim strEngineSize As String = CType(e.Item.FindControl("txtEngineSize"), TextBox).Text
        Dim strFuelType As String = CType(e.Item.FindControl("lstFuelTypes"), DropDownList).SelectedItem.Value

        Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\GCSwebsite.mdb") & ";"
        Dim MySQL As String = "UPDATE Vehicles SET Vehicles.Make = '" & strMake & "', Model = '" & strModel & "', CarYear = '" & strCarYear & "', EngineSize = '" & strEngineSize & "', FuelType = '" & strFuelType & "' WHERE RegNo = '" & strRegNo & "'"
        Dim MyConn As New OleDbConnection(strConn)
        Dim objDR As OleDbDataReader
        Dim Cmd As New OleDbCommand(MySQL, MyConn)

        MyConn.Open()
        objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.Clos eConnection)
        'Finally, set the EditItemIndex to -1 and rebind the DataGrid
        dgVehicleInfo.EditItemIndex = -1
        BindDataVehicleInfo()
    End Sub

    Sub dgVehicleInfo_Delete(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
        'Get the RegNo of the row whose Delete button was clicked
        Dim SelectedRegNo As String = dgVehicleInfo.DataKeys(e.Item.ItemIndex)

        Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\GCSwebsite.mdb") & ";"
        Dim MySQL As String = "DELETE Vehicles.* FROM Vehicles WHERE RegNo = '" & SelectedRegNo & "'"
        Dim MyConn As New OleDbConnection(strConn)
        Dim objDR As OleDbDataReader
        Dim Cmd As New OleDbCommand(MySQL, MyConn)
        MyConn.Open()
        objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.Clos eConnection)
        'Finally, set the EditItemIndex to -1 and rebind the DataGrid
        dgVehicleInfo.EditItemIndex = -1
        BindDataVehicleInfo()
    End Sub

    Sub dgVehicles_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
        ' First, make sure we're NOT dealing with a Header or Footer row
        If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then
            'Now, reference the LinkButton control that the Delete ButtonColumn
            'has been rendered to
            Dim btnDelete As Button = CType(e.Item.Cells(0).FindControl("btnDelete"), Button)
            btnDelete.Attributes.Add("onclick", "return confirm_delete();")
        End If
    End Sub



Cheers!
 
Old April 2nd, 2004, 02:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Do you have output caching declared for this web page?
 
Old April 3rd, 2004, 06:17 AM
Registered User
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

No I havent declared output caching. To be honest I'm not too sure how to use it. It looked up a few things on caching and added the following line to my code:

<%@ OutputCache Duration="60" VaryByParam="none" %>

When I done this, the update and cancel buttons on the datagrid did not respond.

Is the line above what you were suggesting? Do I need to specify something for the 'VaryByParam'?

Thanks
Daryl

 
Old April 3rd, 2004, 07:26 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Output caching would most certainly affect the proper operation of a page.
With that statement you are telling ASP.net to not even RUN that page the next time it's requested. It just takes the cached HTML that the page generates the first time it's run and responds with that instead of processing the page.
 
Old April 4th, 2004, 09:45 AM
Registered User
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ahh I see. I followed a great article available from: http://aspnet.4guysfromrolla.com/articles/040502-1.aspx when creating my datagrids. I think I followed everything that was mention throughout the article, so I cannot understand this problem at all. Have you any suggetions?
 
Old April 10th, 2004, 12:57 PM
Registered User
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can anyone help me out?

Im begging!

 
Old April 10th, 2004, 01:08 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Did you ever turn off the line you said is in there?

<%@ OutputCache Duration="60" VaryByParam="none" %>

This would definately cause problems.

I have skimming the code you first posted, and it looks fine. After you make DB changes (update, delete) you are rebinding the grid. Short of that, I can't imagine what else you need to do.
 
Old April 12th, 2004, 12:10 PM
Registered User
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi planoie,

Yeah I took that out. I only tried it because bmainssuggested it. Yeah I cant work it out either. Its not only on this page that the problem occurs. It is happening on every page that modifies the datagrid.

Thanks for replying
Daryl

 
Old April 12th, 2004, 01:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

I didn't suggest adding output caching, I was wondering if you had it turned on.

Sorry for any inconvenience.

Brian
 
Old April 14th, 2004, 08:02 AM
Registered User
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

There has been slight progess. If i remove Sub BindDataVehicleInfo() and put it's contents inside the Page_Load event - use dgVehicleInfo.DataBind() where Sub BindDataVehicleInfo()was previously referenced, when an item is deleted, the effect is displayed immediately. It does delete all the records however.








Similar Threads
Thread Thread Starter Forum Replies Last Post
"/Modifications" maxshreck BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 October 10th, 2006 01:13 AM
Membership modifications...should I? Tremmorkeep BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 10 September 22nd, 2006 04:20 AM
Showing Hyperlink in Winforms Datagrid control livehed C# 0 January 20th, 2006 01:56 PM
Selectively showing an icon in datagrid GuyB ASP.NET 1.0 and 1.1 Basics 3 November 25th, 2005 01:19 AM
Custom modifications to ThePhile meierk BOOK: ASP.NET Website Programming Problem-Design-Solution 0 October 1st, 2003 02:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.