Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: EDITING A DATAGRID


Message #1 by "J Morrell" <jemuel_morrell@h...> on Wed, 14 Aug 2002 09:05:48 +1200
Hey all

I'd really appreciate some help here if pos.  I am relatively new to aspx, 
and have the following problem.

On a Win2K machine running IIS5.0, I have managed to populate a datagrid 
using a dataset which in turn is populated by querying and Oracle Table.  
When I click on the 'Edit' link within the datagrid, all behaves as 
expected.  The datagrid re-loads, with text boxes in the appropriate row 
ready for editing.  My problem is when I make the edit, then click on the 
'Update' link, only the data from the dataset, not the newly edited 
information is captured, therefore meaning that when the recordset is 
updated, no updates are actually made.  My update code is as follows:


Sub DataGrid2_UpdateCommand(source As Object, e As DataGridCommandEventArgs)

'declare variables
  Dim ConnectionString As String = 
"Provider=MSDAORA.1;Password=r36tkp45;User ID=ego;Data 
Source=testarea;Persist Security Info=True"
  Dim myConnection As oledbconnection
  Dim myCommand As oledbcommand

  'create control variables equalling the edited rowsets controls, in this 
case text boxes
  Dim txtEmail As TextBox = ctype(E.Item.Cells(5).Controls(0),textbox)
  Dim txtExtn As TextBox = ctype(E.Item.Cells(6).Controls(0),textbox)
  Dim txtDD As TextBox = ctype(E.Item.Cells(7).Controls(0),textbox)
  Dim txtAsset As TextBox = ctype(E.Item.Cells(8).Controls(0),textbox)
  dim strX as string = e.item.cells(7).text

  'declare sql update string
  Dim strUpdateStmt As String

  response.write ("Email = " & txtEmail.text & "<br>")
  response.write ("Extn = " & txtExtn.text & "<br>")
  response.write ("DD = " & txtDD.text & "<br>")
  response.write ("Asset = " & txtAsset.text & "<br>")
  response.write ("strX = " & strX & "<br>")


  'response.end
'create update sql
  strUpdateStmt = "UPDATE HCO_USER_DETAILS SET EMAIL = '" & txtEmail.Text & 
"', EXTENSION = '" & txtExtn.Text & "', " _
   & "DIRECT_DIAL = '" & txtDD.text & "', ASSET_NUMBER= '" & txtAsset.text & 
"' " _
   & "WHERE PK=" & E.ITEM.CELLS(1).TEXT
   response.write (strUpdateStmt & "<br>")

    response.write ("strSQL = " & strUpdateStmt & "<br>")

   'set the myConnection object's connection string property
   myConnection = New oledbconnection(ConnectionString)

   'set command object properties, commandtext=strUpdateStmt, connection is 
MyConnection
   myCommand = New oledbcommand(strUpdateStmt, myConnection)

   'open the connection
   myConnection.Open()

   'execute the command as a non-query (action query - update, delete etc)
   myCommand.ExecuteNonQuery()

  'reset the datagrid so that no items are being edited
   DataGrid2.EditItemIndex = -1

  'call the GetResults function
   GetResults()
End Sub

Doing a response.write of the strUpdateStmt writes the SQL to screen, but 
without the edited field data.

Any help will be appreciated

J


_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com

Message #2 by "Payal Parija" <pparija@u...> on Wed, 14 Aug 2002 14:19:41
you need to have a handles after the function otherwise it doesnt know on 
what event does this command has to fire...

or else

in the DataGrid2 javascript declaration....
define OnUpdateCommand = "DataGrid2_UpdateCommand"

this allows the datagrid to know which command to fire.....





Sub DataGrid2_UpdateCommand(source As Object, e As 
DataGridCommandEventArgs)Handles DataGrid2.UpdateCommand

 

I'd really appreciate some help here if pos.  I am relatively new to aspx, 
and have the following problem.

On a Win2K machine running IIS5.0, I have managed to populate a datagrid 
using a dataset which in turn is populated by querying and Oracle Table.  
When I click on the 'Edit' link within the datagrid, all behaves as 
expected.  The datagrid re-loads, with text boxes in the appropriate row 
ready for editing.  My problem is when I make the edit, then click on the 
'Update' link, only the data from the dataset, not the newly edited 
information is captured, therefore meaning that when the recordset is 
updated, no updates are actually made.  My update code is as follows:


Sub DataGrid2_UpdateCommand(source As Object, e As 
DataGridCommandEventArgs)

'declare variables
  Dim ConnectionString As String = 
"Provider=MSDAORA.1;Password=r36tkp45;User ID=ego;Data 
Source=testarea;Persist Security Info=True"
  Dim myConnection As oledbconnection
  Dim myCommand As oledbcommand

  'create control variables equalling the edited rowsets controls, in this 
case text boxes
  Dim txtEmail As TextBox = ctype(E.Item.Cells(5).Controls(0),textbox)
  Dim txtExtn As TextBox = ctype(E.Item.Cells(6).Controls(0),textbox)
  Dim txtDD As TextBox = ctype(E.Item.Cells(7).Controls(0),textbox)
  Dim txtAsset As TextBox = ctype(E.Item.Cells(8).Controls(0),textbox)
  dim strX as string = e.item.cells(7).text

  'declare sql update string
  Dim strUpdateStmt As String

  response.write ("Email = " & txtEmail.text & "<br>")
  response.write ("Extn = " & txtExtn.text & "<br>")
  response.write ("DD = " & txtDD.text & "<br>")
  response.write ("Asset = " & txtAsset.text & "<br>")
  response.write ("strX = " & strX & "<br>")


  'response.end
'create update sql
  strUpdateStmt = "UPDATE HCO_USER_DETAILS SET EMAIL = '" & txtEmail.Text 
& 
"', EXTENSION = '" & txtExtn.Text & "', " _
   & "DIRECT_DIAL = '" & txtDD.text & "', ASSET_NUMBER= '" & txtAsset.text 
& 
"' " _
   & "WHERE PK=" & E.ITEM.CELLS(1).TEXT
   response.write (strUpdateStmt & "<br>")

    response.write ("strSQL = " & strUpdateStmt & "<br>")

   'set the myConnection object's connection string property
   myConnection = New oledbconnection(ConnectionString)

   'set command object properties, commandtext=strUpdateStmt, connection 
is 
MyConnection
   myCommand = New oledbcommand(strUpdateStmt, myConnection)

   'open the connection
   myConnection.Open()

   'execute the command as a non-query (action query - update, delete etc)
   myCommand.ExecuteNonQuery()

  'reset the datagrid so that no items are being edited
   DataGrid2.EditItemIndex = -1

  'call the GetResults function
   GetResults()
End Sub

Doing a response.write of the strUpdateStmt writes the SQL to screen, but 
without the edited field data.

Any help will be appreciated

J


_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com

Message #3 by "J Morrell" <jemuel_morrell@h...> on Thu, 15 Aug 2002 07:48:22 +1200
Hi there

Many thanks for your response.  Firstly, I don't understand what you mean by 
'handles after the function'.  However, this is the code in my datagrid 
declaration

<asp:DataGrid id="DataGrid2" runat="server" Width="1110px" 
BackColor="#FFE0C0" OnUpdateCommand="DataGrid2_UpdateCommand" 
OnEditCommand="DataGrid2_EditCommand" AutoGenerateColumns="False" 
OnCancelCommand="DataGrid2_CancelCommand">

and as you can see, the OnEditCommand calls the funciton 
DataGrid2_EditCommand.  Any other ideas

>From: "Payal Parija" <pparija@u...>
>Reply-To: "aspx_beginners" <aspx_beginners@p...>
>To: "aspx_beginners" <aspx_beginners@p...>
>Subject: [aspx_beginners] Re: EDITING A DATAGRID
>Date: Wed, 14 Aug 2002 14:19:41
>
>you need to have a handles after the function otherwise it doesnt know on
>what event does this command has to fire...
>
>or else
>
>in the DataGrid2 javascript declaration....
>define OnUpdateCommand = "DataGrid2_UpdateCommand"
>
>this allows the datagrid to know which command to fire.....
>
>
>
>
>
>Sub DataGrid2_UpdateCommand(source As Object, e As
>DataGridCommandEventArgs)Handles DataGrid2.UpdateCommand
>
>
>
>I'd really appreciate some help here if pos.  I am relatively new to aspx,
>and have the following problem.
>
>On a Win2K machine running IIS5.0, I have managed to populate a datagrid
>using a dataset which in turn is populated by querying and Oracle Table.
>When I click on the 'Edit' link within the datagrid, all behaves as
>expected.  The datagrid re-loads, with text boxes in the appropriate row
>ready for editing.  My problem is when I make the edit, then click on the
>'Update' link, only the data from the dataset, not the newly edited
>information is captured, therefore meaning that when the recordset is
>updated, no updates are actually made.  My update code is as follows:
>
>
>Sub DataGrid2_UpdateCommand(source As Object, e As
>DataGridCommandEventArgs)
>
>'declare variables
>   Dim ConnectionString As String 
>"Provider=MSDAORA.1;Password=r36tkp45;User ID=ego;Data
>Source=testarea;Persist Security Info=True"
>   Dim myConnection As oledbconnection
>   Dim myCommand As oledbcommand
>
>   'create control variables equalling the edited rowsets controls, in this
>case text boxes
>   Dim txtEmail As TextBox = ctype(E.Item.Cells(5).Controls(0),textbox)
>   Dim txtExtn As TextBox = ctype(E.Item.Cells(6).Controls(0),textbox)
>   Dim txtDD As TextBox = ctype(E.Item.Cells(7).Controls(0),textbox)
>   Dim txtAsset As TextBox = ctype(E.Item.Cells(8).Controls(0),textbox)
>   dim strX as string = e.item.cells(7).text
>
>   'declare sql update string
>   Dim strUpdateStmt As String
>
>   response.write ("Email = " & txtEmail.text & "<br>")
>   response.write ("Extn = " & txtExtn.text & "<br>")
>   response.write ("DD = " & txtDD.text & "<br>")
>   response.write ("Asset = " & txtAsset.text & "<br>")
>   response.write ("strX = " & strX & "<br>")
>
>
>   'response.end
>'create update sql
>   strUpdateStmt = "UPDATE HCO_USER_DETAILS SET EMAIL = '" & txtEmail.Text
>&
>"', EXTENSION = '" & txtExtn.Text & "', " _
>    & "DIRECT_DIAL = '" & txtDD.text & "', ASSET_NUMBER= '" & txtAsset.text
>&
>"' " _
>    & "WHERE PK=" & E.ITEM.CELLS(1).TEXT
>    response.write (strUpdateStmt & "<br>")
>
>     response.write ("strSQL = " & strUpdateStmt & "<br>")
>
>    'set the myConnection object's connection string property
>    myConnection = New oledbconnection(ConnectionString)
>
>    'set command object properties, commandtext=strUpdateStmt, connection
>is
>MyConnection
>    myCommand = New oledbcommand(strUpdateStmt, myConnection)
>
>    'open the connection
>    myConnection.Open()
>
>    'execute the command as a non-query (action query - update, delete etc)
>    myCommand.ExecuteNonQuery()
>
>   'reset the datagrid so that no items are being edited
>    DataGrid2.EditItemIndex = -1
>
>   'call the GetResults function
>    GetResults()
>End Sub
>
>Doing a response.write of the strUpdateStmt writes the SQL to screen, but
>without the edited field data.
>
>Any help will be appreciated
>
>J
>
>
>_________________________________________________________________
>Join the world?s largest e-mail service with MSN Hotmail.
>http://www.hotmail.com
>




_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com


  Return to Index