Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Edit is a DataGrid
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00876073
Message ID:
00876102
Vues:
9
Hi Fred,

I'm assuming that you have set the event to execute on the DataGrid when editing. You set that with OnUpdateCommand="MyMethod". In method you then find the controls and extract the values from them. There is a MSDN article that I wrote that provides an example of how to do this. It is the first example shown. Here is the link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfoxgen7/html/usingaspnetwithvfp7.asp

Here is the code that runs in the Code-Behind method called when the Editing in the grid is completed:
Dim objCompanyCtrl As TextBox
Dim objContactCtrl As TextBox
Dim objCustIDCtrl As Label

' Assign the objects to each object in the edited row
objCompanyCtrl = _
     CType(objArgs.Item.FindControl("txtCompany"), TextBox)
objContactCtrl = _
     CType(objArgs.Item.FindControl("txtContact"), TextBox)
objCustIDCtrl = _
     CType(objArgs.Item.FindControl("lblCustID"), Label)

' Create update select statement
strUpdateSelect = "UPDATE Customer SET Company='" & _
     objCompanyCtrl.Text + "', " + "Contact='" & _
     objContactCtrl.Text + "' " + "WHERE Cust_ID='" & _
     objCustIDCtrl.Text + "'"
Hopefully this helps.

>Against my better judgment we are entering data in a datagrid.
>
>And, ofcourse, we are having a problem finding the values we just entered into the grid in edit mode.
>
>In the UpdateCommand method, we pass in the object reference to the grid and the DataGridCommandEventsArgs. From the DataGridCommandEventsArgs object we know the command that was issued and the ItemIndex number (Row number) in the grid. We can locate the cells that are being edited in the grid with the following lines of code.
>
>
>// First column is hidden and read only, contains the PK for the table.
>oHoliday.iHolidayPK = this.grdHolidays.Items[e.Item.ItemIndex].Cells[0].Text
>
>// Second column contains the date
>oHoliday.daHolidayDate = this.grdHolidays.Items[e.Item.ItemIndex].Cells[1].Text
>
>// Third Column contains the Holiday Title
>oHoliday.sHolidayDescription = this.grdHolidays.Items[e.Item.ItemIndex].Cells[2].Text
>
>When we view the values pulled from the grid, it is the original starting value; not the values entered by the user. We then looked and said, let's try binding the data again before checking the values of the celss and see what that does (as per an example in a book).
>
>this.grdHolidays.BindData()
>
>After that, the datasource from the grid is blank, there are no rows to operate on.
>
>We are we missing?
>
>Thank You Very Much in advance.
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform