Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Howzit #1
Problem when updating a datagrid
Using the sample walkthrough:
Walkthrough: Using a DataGrid Web Control to Read and Write Data
This is the Update command code:
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.UpdateCommand
Dim categoryName, categoryDescription As String
' Gets the value of the key field of the row being updated
Dim key As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
' Gets get the value of the controls (textboxes) that the user
' updated. The DataGrid columns are exposed as the Cells collection.
' Each cell has a collection of controls. In this case, there is only
one
' control in each cell -- a TextBox control. To get its value,
' you copy the TextBox to a local instance (which requires casting)
' and extract its Text property.
'
' The first column -- Cells(0) -- contains the Update and Cancel
buttons.
Dim tb As TextBox
' Gets the value the TextBox control in the third column
tb = CType(e.Item.Cells(2).Controls(0), TextBox)
categoryName = tb.Text
' Gets the value the TextBox control in the fourth column
tb = CType(e.Item.Cells(3).Controls(0), TextBox)
categoryDescription = tb.Text
' Finds the row in the dataset table that matches the
' one the user updated in the grid. This example uses a
' special Find method defined for the typed dataset, which
' returns a reference to the row.
Dim r As dsCategories.CategoriesRow
r = DsCategories1.Categories.FindByCategoryID(key)
' Updates the dataset table.
r.CategoryName = categoryName
r.Description = categoryDescription
' Calls a SQL statement to update the database from the dataset
SqlDataAdapter1.Update(DsCategories1)
' Takes the DataGrid row out of editing mode
DataGrid1.EditItemIndex = -1
' Refreshes the grid
DataGrid1.DataBind()
End Sub
If the datagrid's scourse is a single table then it works fine, but as soon
as it is based on a query or procedure containing joined tables then I get
an error on this line:
r = DsCategories1.Categories.FindByCategoryID(key)
Stating that "FindByCategoryID(key)" is not a member of
"DsCategories1.Categories"
Why do I get this error, and how do I resolve it.
Please try and base your sollution on VB.Net.
Thanks
Howzit Guest
-
updating datagrid with JOIN query
When making an editable datagrid, I've gotten pretty good and handling the function I call in the OnUpdateCommand event. I can update a table easily... -
Problem keeping the datagrid view intact after updating
>NET 2003, vb code behind. I am having a problem with the look of a page with a datagrid. I have the grid populated, and it can be a couple of... -
problem updating in datagrid ??
The guts of the below asp.net vb code was pieced together from another thread - all due credit to it's original author. Thank you! I've... -
Datagrid not updating database
I am using a dropdown box to query a database and populate a datagrid. Everything works except the update button. When the update button is... -
Updating database through a datagrid using checkboxes
I need to update items in a database queue, so I am attempting to write a ASP.NET utility to do this instead of the users just typing SQL. I am...



Reply With Quote

