Hi,
Right click on the datagrid and select property grid. Under columns
expand the button column and move edit, update, and cancel to the selected
columns. Here is some code on how to handle the edit. I left the code on
how to handle paging just in case you needed it. Please note i left the
code to edit the actual datasource up to you in the updateitem event. I can
provide code if needed.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Me.IsPostBack Then
doDataBind()
End If
End Sub
Protected Sub doDataBind()
Dim bc As BoundColumn
Dim ds As DataSet
Dim cn As New SqlConnection("server=localhost;" & _
"Integrated Security=SSPI;Initial Catalog=GolfArticles")
Dim da As New SqlDataAdapter("Select * from Customer ORDER BY CustomerID",
cn)
ds = New DataSet("Customers")
da.Fill(ds, "Customers")
Me.DataGrid1.DataSource = ds.Tables("Customers").DefaultView
DataGrid1.DataBind()
Label1.Text = ds.GetXml
End Sub
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
DataGrid1.PageIndexChanged
' For the DataGrid control to navigate to the correct page when
' paging is allowed, the CurrentPageIndex property must be updated
' programmatically. This process is usually accomplished in the
' event-handling method for the PageIndexChanged event.
' Set CurrentPageIndex to the page the user clicked.
DataGrid1.CurrentPageIndex = e.NewPageIndex
' Rebind the data to refresh the DataGrid control.
doDataBind()
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
doDataBind()
End Sub
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.UpdateCommand
'
' Update command goes here
'
DataGrid1.EditItemIndex = -1
doDataBind()
End Sub
Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
doDataBind()
End Sub
Ken
-------------------------
I have a datagrid on a webform that will allow the user to
edit data in a list. I have added the edit column in as a
link, but when it is clicked nothing happens. Do I need
to set something else in the Columns property or is it a
property of the dataset that needs changing?
Thanks
Helen