Editing a row in a datagrid

Discussion in 'ASP .Net' started by =?Utf-8?B?bWFyZWFs?=, May 2, 2005.

  1. I have coded an updatable datagrid and can’t seem to obtain the original
    value from the cell in order to run an update on the database. I can obtain
    the (new) value typed by the user (see DataGrid1_Update), but I also need the
    original/old value. How can I obtain it?

    void DataGrid1_Edit(object sender, DataGridCommandEventArgs e)
    {
    DataGrid1.EditItemIndex = (int) e.Item.ItemIndex;
    ddlTransmissionName_SelectedIndexChanged(sender, (System.EventArgs) e);
    }

    void DataGrid1_Update(object sender, DataGridCommandEventArgs e)
    {
    System.Web.UI.WebControls.TextBox tbFieldName = new TextBox();
    tbFieldName = e.Item.FindControl("txtFieldName") as
    System.Web.UI.WebControls.TextBox;
    string sFieldName = tbFieldName.Text;

    DataGrid1.EditItemIndex = -1;
    ddlTransmissionName_SelectedIndexChanged(sender, (System.EventArgs) e);
    }
    =?Utf-8?B?bWFyZWFs?=, May 2, 2005
    #1
    1. Advertising

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

    Elton W Guest

    Hi Mareal,

    You can save the datagrid's data source, e.g. datatable
    (original/old value), in Session or Context object. Then
    in Update method retrieve corresponding value from the
    data source.

    HTH


    Elton Wang



    >-----Original Message-----
    >I have coded an updatable datagrid and canâ?Tt seem to

    obtain the original
    >value from the cell in order to run an update on the

    database. I can obtain
    >the (new) value typed by the user (see DataGrid1_Update),

    but I also need the
    >original/old value. How can I obtain it?
    >
    >void DataGrid1_Edit(object sender,

    DataGridCommandEventArgs e)
    >{
    >DataGrid1.EditItemIndex = (int) e.Item.ItemIndex;
    >ddlTransmissionName_SelectedIndexChanged(sender,

    (System.EventArgs) e);
    >}
    >
    >void DataGrid1_Update(object sender,

    DataGridCommandEventArgs e)
    >{
    >System.Web.UI.WebControls.TextBox tbFieldName = new

    TextBox();
    >tbFieldName = e.Item.FindControl("txtFieldName") as
    >System.Web.UI.WebControls.TextBox;
    >string sFieldName = tbFieldName.Text;
    >
    >DataGrid1.EditItemIndex = -1;
    >ddlTransmissionName_SelectedIndexChanged(sender,

    (System.EventArgs) e);
    >}
    >
    >.
    >
    Elton W, May 3, 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. Alex
    Replies:
    1
    Views:
    2,165
    Ken Cox [Microsoft MVP]
    Oct 6, 2003
  2. Henri
    Replies:
    0
    Views:
    589
    Henri
    Aug 3, 2004
  3. Bazza Formez
    Replies:
    4
    Views:
    400
    Vanni Tomezzoli
    Dec 9, 2004
  4. Andrew Jocelyn
    Replies:
    2
    Views:
    1,520
    Allen Chen [MSFT]
    Apr 27, 2009
  5. D
    Replies:
    0
    Views:
    203
Loading...

Share This Page