DataGrid.UpdateCommand Can't Get Updated Values From Textbox Contr

Discussion in 'ASP .Net' started by =?Utf-8?B?TmV3YXNwcw==?=, Jun 12, 2004.

  1. 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.OleDb
    Imports System.Web.UI.WebControls

    Public Class PassengerProcesses
    Inherits System.Web.UI.Page

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents DG As System.Web.UI.WebControls.DataGrid

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region
    Dim Cn As New OleDbConnection

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    'If Not IsPostBack Then
    Cn.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;Data Source='" & Server.MapPath("db/db.mdb") & "'"
    DB()
    'End If
    End Sub


    Private Sub DB()
    Dim DA As New OleDbDataAdapter
    Dim DS As New System.Data.DataSet
    Dim Cmd As New OleDbCommand("Select * from Yolcu", Cn)
    DA.SelectCommand = Cmd
    DA.Fill(DS)
    DG.DataSource = DS
    DG.PageSize = 1
    DG.PagerStyle.Mode = PagerMode.NumericPages
    DG.PagerStyle.PageButtonCount = 10
    DG.DataBind()
    Cn.Open()
    If DG.EditItemIndex > -1 Then
    Dim ColumnCounter As Byte
    For ColumnCounter = 2 To DG.Items(DG.EditItemIndex).Cells.Count - 1
    If DG.Items(DG.EditItemIndex).Cells(ColumnCounter).HasControls Then
    'Response.Write(CType(DG.Items(DG.EditItemIndex).Cells(4).Controls(0), TextBox).Text)
    CType(DG.Items(DG.EditItemIndex).Cells(ColumnCounter).Controls(0), TextBox).CssClass = "input_normal"
    End If
    Next
    CType(DG.Items(DG.EditItemIndex).Cells(2).Controls(0), TextBox).Enabled = False
    End If
    Cn.Close()
    End Sub

    'Private Sub DG_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles DG.ItemDataBound
    ' If e.Item.DataSetIndex > -1 Then
    ' e.Item.Cells(2).Text = DataBinder.Eval(e.Item.DataItem, "ProPhoto", "<img src=""data\Products\PictureMovie\{0}"">")
    ' End If
    'End Sub

    Private Sub DG_PageIndexChanged(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DG.PageIndexChanged
    DG.CurrentPageIndex = e.NewPageIndex
    DB()
    End Sub
    'Public Sub ABC(ByVal sender As Object, ByVal e As System.EventArgs) Handles BT.Click
    'Response.Write(DG.Items(0).Controls(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.WebControls.DataGridCommandEventArgs) Handles DG.EditCommand
    DG.EditItemIndex = e.Item.ItemIndex
    DB()
    End Sub

    Private Sub DG_Update(ByVal sender As System.Object, ByVal E As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DG.UpdateCommand
    Dim ID As TextBox = CType(e.Item.Cells(2).Controls(0), TextBox)
    Dim Ad As TextBox = CType(e.Item.Cells(3).Controls(0), TextBox)
    Dim Soyad As TextBox = CType(e.Item.Cells(4).Controls(0), TextBox)
    Dim Adres As TextBox = CType(e.Item.Cells(5).Controls(0), TextBox)
    Dim Tel As TextBox = CType(e.Item.Cells(6).Controls(0), TextBox)
    Dim Email As TextBox = CType(e.Item.Cells(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(SQLCmd, Cn)
    AffectedRows = CmdUD.ExecuteNonQuery()
    DG.EditItemIndex = -1
    Response.Write("<p class=""genelyazi"" 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=""genelyazi"" 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.Count)
    'Dim TB As TextBox = CType(e.Item.Cells(0).Controls(0), TextBox)
    'TB.TextMode = TextBoxMode.MultiLine
    'TB.Rows = 3
    End Sub

    Private Sub DG_Cancel(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles DG.CancelCommand
    DG.EditItemIndex = -1
    DB()
    End Sub
    End Class
     
    =?Utf-8?B?TmV3YXNwcw==?=, Jun 12, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?T3plcg==?=

    DataGrid.UpdateCommand I can't get updated values

    =?Utf-8?B?T3plcg==?=, Jun 12, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    542
    =?Utf-8?B?T3plcg==?=
    Jun 12, 2004
  2. D. Shane Fowlkes
    Replies:
    3
    Views:
    569
    Scott M.
    Jul 8, 2004
  3. srathin

    DataGrid1 UpdateCommand calling DataGrid2 UpdateCommand

    srathin, Apr 9, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    179
    srathin
    Apr 9, 2005
  4. srathin

    DataGrid1 UpdateCommand calling DataGrid2 UpdateCommand

    srathin, Apr 9, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    164
    srathin
    Apr 11, 2005
  5. Ashok
    Replies:
    2
    Views:
    176
    Ashok
    May 10, 2005
Loading...

Share This Page