473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DataGrid.UpdateCommand I can't get updated values

Hi guys,
I need some help. In my datagrid's updatecommand event i'm trying to get textboxes values and also do it. But when i update the values in textboxes and fire the event, I can't get the updated values. 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).Ha sControls Then
'Response.Write(CType(DG.Items(DG.EditItemIndex).C ells(4).Controls(0), TextBox).Text)
CType(DG.Items(DG.EditItemIndex).Cells(ColumnCount er).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.DataGridPageChangedEvent Args) 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

Nov 18 '05 #1
0 1517

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: VIJAY KUMAR | last post by:
Hi, I Have a values in a datagrid. I want to edit the values in a datagrid (Say Company="Techgene" which is primary key). Before Update the selected Record I have to get the Orignal VAlue ....
4
by: Angel | last post by:
How can I update the datatable with the datagrid values after the datagrid itself has been modified.? I assume it's not automatically done. Thanks.
13
by: abdoly | last post by:
i wrote a code to update datagrid with the datagrid updatecommand but i cant get the updated values after being update that is the code private void DataGrid1_UpdateCommand(object source,...
0
by: Newasps | last post by:
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...
1
by: MrMike | last post by:
Hi. My application has dozens of datagrids but for some reason an exception occurs when one of them is updated. When a user edits a datagrid row and then clicks 'Update' the following exception...
5
by: Hennie | last post by:
When trying to update a record in an editable datagrid I ran into a few problems. My update procedure is just not working. Can someone please have a look at my code and see what am I doing wrong....
1
by: Rich | last post by:
Hello, I can update a dataset from my client app using a dataAdapter.Updatecommand when I add parameter values outside of the param declaration. But If I add the param values inline with the...
6
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection =...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.