Hi guys,
I have a problem with UpdateCommand Event. In tihs event Ä°'m creating required controls to get that controls' values and also get them. But when I try to get updated values I'm getting the first values for each control. Please help me. Thanks for any help. Bye
Ozer
And here's my code:
Imports System
Imports System.Data
Imports System.Data.Ole Db
Imports System.Web.UI.W ebControls
Public Class PassengerProces ses
Inherits System.Web.UI.P age
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
End Sub
Protected WithEvents DG As System.Web.UI.W ebControls.Data Grid
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region
Dim Cn As New OleDbConnection
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
'If Not IsPostBack Then
Cn.ConnectionSt ring = "Provider=Micro soft.JET.OLEDB. 4.0;Data Source='" & Server.MapPath( "db/db.mdb") & "'"
DB()
'End If
End Sub
Private Sub DB()
Dim DA As New OleDbDataAdapte r
Dim DS As New System.Data.Dat aSet
Dim Cmd As New OleDbCommand("S elect * from Yolcu", Cn)
DA.SelectComman d = Cmd
DA.Fill(DS)
DG.DataSource = DS
DG.PageSize = 1
DG.PagerStyle.M ode = PagerMode.Numer icPages
DG.PagerStyle.P ageButtonCount = 10
DG.DataBind()
Cn.Open()
If DG.EditItemInde x > -1 Then
Dim ColumnCounter As Byte
For ColumnCounter = 2 To DG.Items(DG.Edi tItemIndex).Cel ls.Count - 1
If DG.Items(DG.Edi tItemIndex).Cel ls(ColumnCounte r).HasControls Then
'Response.Write (CType(DG.Items (DG.EditItemInd ex).Cells(4).Co ntrols(0), TextBox).Text)
CType(DG.Items( DG.EditItemInde x).Cells(Column Counter).Contro ls(0), TextBox).CssCla ss = "input_norm al"
End If
Next
CType(DG.Items( DG.EditItemInde x).Cells(2).Con trols(0), TextBox).Enable d = False
End If
Cn.Close()
End Sub
'Private Sub DG_ItemDataBoun d(ByVal sender As Object, ByVal e As DataGridItemEve ntArgs) Handles DG.ItemDataBoun d
' If e.Item.DataSetI ndex > -1 Then
' e.Item.Cells(2) .Text = DataBinder.Eval (e.Item.DataIte m, "ProPhoto", "<img src=""data\Prod ucts\PictureMov ie\{0}"">")
' End If
'End Sub
Private Sub DG_PageIndexCha nged(ByVal sender As System.Object, ByVal e As System.Web.UI.W ebControls.Data GridPageChanged EventArgs) Handles DG.PageIndexCha nged
DG.CurrentPageI ndex = e.NewPageIndex
DB()
End Sub
'Public Sub ABC(ByVal sender As Object, ByVal e As System.EventArg s) Handles BT.Click
'Response.Write (DG.Items(0).Co ntrols(0))
'Dim TB1 As TextBox = CType(DG.Items( 0).Controls(0), TextBox)
'End Sub
Private Sub DG_Edit(ByVal sender As System.Object, ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles DG.EditCommand
DG.EditItemInde x = e.Item.ItemInde x
DB()
End Sub
Private Sub DG_Update(ByVal sender As System.Object, ByVal E As System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles DG.UpdateComman d
Dim ID As TextBox = CType(e.Item.Ce lls(2).Controls (0), TextBox)
Dim Ad As TextBox = CType(e.Item.Ce lls(3).Controls (0), TextBox)
Dim Soyad As TextBox = CType(e.Item.Ce lls(4).Controls (0), TextBox)
Dim Adres As TextBox = CType(e.Item.Ce lls(5).Controls (0), TextBox)
Dim Tel As TextBox = CType(e.Item.Ce lls(6).Controls (0), TextBox)
Dim Email As TextBox = CType(e.Item.Ce lls(7).Controls (0), TextBox)
Dim AffectedRows As Int32
Cn.Open()
Try
Dim SQLCmd As String = "UPDATE Yolcu SET Adi='" & Ad.Text & "',Soyadi=' " & Soyad.Text & "',Adresi=' " & Adres.Text & "',Telefon= '" & Tel.Text & "',Email='" & Email.Text & "' WHERE YolcuID=" & ID.Text
Response.Write( SQLCmd)
Dim CmdUD As New OleDbCommand(SQ LCmd, Cn)
AffectedRows = CmdUD.ExecuteNo nQuery()
DG.EditItemInde x = -1
Response.Write( "<p class=""genelya zi"" align=""center" ">")
Response.Write( "Kayıt işlemi başarıyla tamamlandı.")
Response.Write( "</p>")
Catch ex As Exception
Response.Write( ex.Source & " " & ex.Message)
Response.Write( "<p class=""genelya zi"" align=""center" ">")
Response.Write( "Hata oluştu. Kayıt işlemi başarısız.")
Response.Write( "</p>")
End Try
Cn.Close()
DB()
'Response.Write (e.Item.Cells.C ount)
'Dim TB As TextBox = CType(e.Item.Ce lls(0).Controls (0), TextBox)
'TB.TextMode = TextBoxMode.Mul tiLine
'TB.Rows = 3
End Sub
Private Sub DG_Cancel(ByVal sender As Object, ByVal e As DataGridCommand EventArgs) Handles DG.CancelComman d
DG.EditItemInde x = -1
DB()
End Sub
End Class