Editing Datagrids

  • Thread starter Thread starter Helen Trim
  • Start date Start date
H

Helen Trim

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
 
Helen,

Yes there is a property what is by default false by other controls than the
different buttons which is "autopostback"

I hope this helps?

Cor


"Helen Trim"
 
Thanks for the suggestion, but a datagrid doesn't have an
AutoPostback property.

Anything else I can do?
 
Helen,

I thought you where talking about the list and I thougth it was the
dataslist that you wanted to activate.

For the datagrid you would have to add a button column, what is the most
easy to do using the designer, which has a kind of wizard for that (look
beneath in the property box for that).
(And the buttons have autopostback standard activated)

I hope this helps?

Cor
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top