Why databind is required while editing datagrid?

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
 
E

Elton Wang

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)
 

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

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top