Click to See Complete Forum and Search --> : Updaing on a details view


KMekgwe
04-12-2007, 09:43 AM
I have the following code which enables the fields to be edited within the DV:
Dim gv0 As DetailsView = CType(sender, DetailsView)
gv0.ChangeMode(DetailsViewMode.Edit)

Dim obj As Businesslayer.Clients = New Businesslayer.Clients
Dim ds As Data.DataSet
ds = obj.GetClientsDetails(gv0.SelectedValue.ToString())
obj = Nothing
DetailsView1.DataSource = ds
DetailsView1.DataBind()

Could you pls help me with the itemupdating event sample code so that when i click the update button the information must be updated.
thank you

PeOfEo
04-12-2007, 10:24 AM
Here is a little bit of code that shows a simplistic way to do it:
http://quickstarts.asp.net/QuickStartv20/util/srcview.aspx?path=~/aspnet/samples/data/GridViewMasterDetailsEdit.src
And here is a more in-depth article:
http://msdn2.microsoft.com/en-us/library/aa479325.aspx#detailsview_topic5

lmf232s
04-12-2007, 03:45 PM
KMekgwe,
You just need to place a linkbutton, button, imagebutton, etc in your details view and set the commandname="update".

When this button is then clicked it will fire this event (Where dvTest is the name of your details view)

Protected Sub dvTest_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles dvTest.ItemUpdating

End Sub


In this event you can get the values of your fields (Textbox, Label, etc) and then do your DB Update. My Db Code is just to show you where it would be done and not to use my syntax exactly as im calling subs with in classes to execute my queries.

'Code in the ItemUpdating Sub
Dim txtFirstName as String = CType(Me.dvTest.FindControl("txtFirstName"), TextBox).Text.ToString()
Dim txtLastName as String = CType(Me.dvTest.FindControl("txtLastName"), TextBox).Text.ToString()

'DB ENTRY
Dim Values() as String = {txtFirstName, txtLastName}
Dim bRet as Boolean = _SpHelper.ExecuteAnySp2("sp_SomeUpdate", Values)
If bRet Then
'Success
Else
'Failed
End If

KMekgwe
04-13-2007, 02:49 AM
The thing is i'm using 3-tier architecture therefore what i have done is that i have my update statement in the business layer which is as follows:

Public Function UpdateclientDetails(ByVal Type As String, ByVal Email As String, ByVal Telephone As String, ByVal Fax As String, ByVal location As String, ByVal city As String, ByVal RegNo As String, ByVal postal As Integer, ByVal CID As Integer) As Data.DataSet

Dim strSQL As String
Dim obj As Datalayer.Database = New Datalayer.Database
strSQL = "Update Client set ClientType = '" & Type & "',EmailAddress = '" & Email & "',TelephoneNumber = '" & Telephone & "',FaxNumber = '" & Fax & "',Location = '" & location & "',City = '" & city & "',ClientRegNumber = '" & RegNo & "',PostalCode = '" & postal & "' where ClientID ='" & CID & "'"
UpdateclientDetails = obj.GetDataSet(strSQL)
obj.Close()
Exit Function
End Function
The problem is that the application complains about argument not specified for parameters
please help
thanks