473,583 Members | 3,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid.Update Command Can't Get Updated Values From Textbox Contr

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

Nov 18 '05 #1
0 1805

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

Similar topics

2
304
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 . Based on this, I can updated the new value. My Problem is how can i get the value in the datagrid?
13
7663
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, System.Web.UI.WebControls.DataGridCommandEventArgs e) TextBox temp temp=(TextBox)e.Item.Cells.Controls String str=temp.Text; str always returnt the old...
0
1527
by: Ozer | last post by:
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
2
2210
by: Joe Au | last post by:
I follow the Walkthrough documented on Visual Studio to create an editable data grid but it does not work on getting the value of the textbox in the data grid. The code is copied here. I mark "*****" at which the categoryName always get the past value no matter what it has been changed. How do I fix it? Thanks. Joe. Private Sub...
1
1586
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 occurs: --------------------- "Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values....
5
1860
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. I had to set the datagrid's DataKeyField to MailSubscriberID manually since vs does not do it automatically. Thanks
9
2712
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 code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not...
23
1934
by: tanya2001 | last post by:
hi all.. I am trying to update my datagrid in my webform...but its not getting updated..though in the database it removing the <null> and inserting a blank field....its not taking the input which m typing...can sombody plz help me out in this..i need help urgently I am posting the code in vb.net for the webform as well as html Protected Sub...
2
1318
by: slinky | last post by:
I had a successfully deployed datagrid reading an XML file and showing the data: Private Function MakeDataView() as DataView Dim myDataSet As New DataSet() myDataSet.ReadXml(Server.MapPath("TimberSales.xml")) Dim view As DataView = New DataView(myDataSet.Tables(0)) view.AllowDelete = False view.AllowEdit = True view.AllowNew = False
0
8184
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7936
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8195
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5375
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3820
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3845
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1434
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1158
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.