Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
More on the DataGrid
Message
From
29/10/2003 07:34:26
Jacci Adams
Lindsay-Adams Consulting
Louisville, Ohio, United States
 
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00840918
Message ID:
00843987
Views:
26
This message has been marked as the solution to the initial question of the thread.
Hi Joe,

>Yes I created the template in design mode. However the grid is filled from a product table and when the user selects a product I need the quantity to be written to the purchase order table. I hope this makes it more clear.
>

What you need to do to access the values in the grid is something like the following.


Private Sub SaveData
Dim txtFormFieldValue, txtStudentFormDetailsDBID, txtFormFieldTagName As TextBox
Dim strFormFieldValue, strStudentFormDetailsDBID, strFormFieldTagName As String

Dim grdItem As DataGridItem
For Each grdItem In Me.DataGrid1.Items

'-- not sure if this IF is really necessary. I haven't tested it without it.
If grdItem.ItemType = ListItemType.Item Or grdItem.ItemType = ListItemType.AlternatingItem Then

txtStudentFormDetailsDBID = grdItem.Cells(0).FindControl("txtStudentFormDetails_DBID")
strStudentFormDetailsDBID = txtStudentFormDetailsDBID.Text

txtFormFieldValue = grdItem.Cells(0).FindControl("txtFormFieldValue")
strFormFieldValue = txtFormFieldValue.Text

txtFormFieldTagName = grdItem.Cells(0).FindControl("txtFormFieldTagName")
strFormFieldTagName = txtFormFieldTagName.Text

'-- method that updates the SQL server data for that row
SpEdObj.UpdateStudentFormDetails(strStudentFormDetailsDBID, StudentFormDBID, strFormFieldTagName, strFormFieldValue, Session("UserID"))
End If

Next

End Sub



If you are using the DataGrid's native UpdateCommand method, do something like the following:


Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim SpEdObj As New StudentFormsClass(Session("cn"))
Dim txtFormFieldValue, txtStudentFormDetailsDBID, txtFormFieldTagName As TextBox
Dim strFormFieldValue, strStudentFormDetailsDBID, strFormFieldTagName As String

txtStudentFormDetailsDBID = e.Item.FindControl("updStudentFormDetailsDBID")
strStudentFormDetailsDBID = txtStudentFormDetailsDBID.Text
txtFormFieldValue = e.Item.FindControl("updFormFieldValue")
strFormFieldValue = txtFormFieldValue.Text
txtFormFieldTagName = e.Item.FindControl("updFormFieldTagName")
strFormFieldTagName = txtFormFieldTagName.Text

'-- StudentFormDBID is a property on the form
SpEdObj.UpdateStudentFormDetails(strStudentFormDetailsDBID, StudentFormDBID, strFormFieldTagName, strFormFieldValue, Session("UserID"))
'SpEdObj.SaveStudentFormDetail(myFormDetailDS)

'-- go get the updated information
myFormDetailDS = SpEdObj.getStudentFormDetailNoDem(StudentFormDBID)

' repopulate the data grid to reflect the changed row
DataGrid1.EditItemIndex = -1
Me.BindGrid()

End Sub



I've only been doing .NET for 4 months. These may not be the most elegant solutions, but for now they are the only ones I know, and they work for me. We've been using the DataGrid quite a bit and are getting more and more familiar with the power of it.

HTH,
Jacci
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform