 |
| 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
|
|
|
|

April 1st, 2004, 03:31 PM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
|

April 2nd, 2004, 02:03 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Do you have output caching declared for this web page?
|
|

April 3rd, 2004, 06:17 AM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 3rd, 2004, 07:26 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|
|

April 4th, 2004, 09:45 AM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

April 10th, 2004, 12:57 PM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Can anyone help me out?
Im begging!
|
|

April 10th, 2004, 01:08 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|
|

April 12th, 2004, 12:10 PM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 12th, 2004, 01:52 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
I didn't suggest adding output caching, I was wondering if you had it turned on.
Sorry for any inconvenience.
Brian
|
|

April 14th, 2004, 08:02 AM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|
 |