Why databind is required while editing datagrid?

Discussion in 'ASP .Net' started by =?Utf-8?B?QWF5dXNoIFB1cmk=?=, Mar 19, 2005.

  1. 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
     
    =?Utf-8?B?QWF5dXNoIFB1cmk=?=, Mar 19, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?QWF5dXNoIFB1cmk=?=

    Elton Wang Guest

    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


    >-----Original Message-----
    >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
    >.
    >
     
    Elton Wang, Mar 19, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,996
    Smokey Grindel
    Dec 2, 2006
  2. tshad
    Replies:
    1
    Views:
    777
    Alexey Smirnov
    Feb 10, 2010
  3. Sriram
    Replies:
    0
    Views:
    113
    Sriram
    Jun 2, 2004
  4. Michael
    Replies:
    0
    Views:
    226
    Michael
    Dec 29, 2003
  5. Sriram
    Replies:
    0
    Views:
    119
    Sriram
    Jun 1, 2004
Loading...

Share This Page