Why databind is required while editing datagrid?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I was going through an article on datagrid control in ASP.NET and found the
use of databind a bit confusing.
So the default behavior in a editable datagrid row is to show a Update and a
Cancel Button when a user wants to edit the datagrid.
What I found confusing was the use of databinding when this cancel button is
pressed. When we are pressing the Cancel button we are not changing the
datasource...then why do we need to re-bind the web control to the datasource.

DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()


Similarily we use databind to re-bind the datagrid, when the user clicks the
row he wants to edit.

DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()

What am I missing here?

Regards,
-Aayush
 
Hi Aayush,

Binding a datagrid's underlying data source happens in
datagrid.DataSource = dataObject

rather than in

datagrid.DataBind()

The datagrid.DataBind() is only process of datagrid. For
example, when in Edit event it sets

DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()

After processing, the selected row becomes eatable row
(with editable textboxes and Update, Cancel buttons).

HTH

Elton Wang
(e-mail address removed)
 
Back
Top