DataGrid easy Edit-Update using ADO.NET/DataGrid functionality C#?

Ask a Question related to ASP.NET, Design and Development.

  1. #1

    Default DataGrid easy Edit-Update using ADO.NET/DataGrid functionality C#?

    Hi, so I am using built in Edit, Delete, Update i.e.
    OnEditCommand="DataGrid1_Edit" OnUpdateCommand="DataGrid1_Update" with
    handler
    question below in regards to the actual update after edit

    //called by the handler deletes row no problem and updates DB no
    problem
    private void DeleteItem(DataGridCommandEventArgs e)
    {
    DataRow dr = dsEmployees1.Tables["Employees"].Rows[e.Item.ItemIndex];
    dr.Delete();
    sqlDataAdapter1.Update(dsEmployees1, "Employees");
    DataGrid1.EditItemIndex = -1;
    DataGrid1.DataBind();
    }

    public void DataGrid1_Edit(Object sender, DataGridCommandEventArgs E)
    {
    DataGrid1.EditItemIndex = (int)E.Item.ItemIndex;
    DataGrid1.DataBind();
    }

    //NOW WHAT DO I NEED TO DO HERE TO ACTUALLY UPDATE THE ROW?
    //IS THE ONLY WAY TO DO IT IS by getting individual column values and
    //constructing SQL statement? IS there a way to call some kind of
    update to accept and commit entered changes? done through Edit?
    public void DataGrid1_Update(Object sender, DataGridCommandEventArgs
    E)
    {
    DataGrid1.EditItemIndex = (int)E.Item.ItemIndex;
    DataRow dr = dsEmployees1.Tables["Employees"].Rows[DataGrid1.EditItemIndex];
    sqlDataAdapter1.Update(dsEmployees1, "Employees");
    // Rebind the data source to refresh the DataGrid control.
    DataGrid1.EditItemIndex = -1;
    DataGrid1.DataBind();
    }
    Kostia Guest

  2. Similar Questions and Discussions

    1. Datagrid Edit, Insert & Update Checkbox (ASP.NET Using VB.NET)
      Hi you guys. If you could possible help me here. I am quite new to .NET coming over from VB and with limited ASP development. I am having a problem...
    2. How to add a Dropdown list to a datagrid at runtime (dynamic) without using template columns in ASP.NET and still have the ability to us the datagrid Update event.
      How to add a Dropdown list to a datagrid at runtime (dynamic) without using template columns in ASP.NET and still have the ability to us the...
    3. Datagrid disappearing on Edit, Update, or Cancel
      I had an application developed on asp.net 1.0. I recently moved the application to 2003 server and asp.net 1.1. The application loads fine, but...
    4. Adding javascript function to update button in datagrid edit row
      I'd like to run a javascript function when you click the update button on an edit row, but I've no idea how I'd set it. Can't find any examples,...
    5. To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible?
      Hello, I am searching the whole Internet for a good example how to edit/update a DataGrid in a DataGrid (nested DataGrid). I know how to...
  3. #2

    Default Re: DataGrid easy Edit-Update using ADO.NET/DataGrid functionality C#?

    > //NOW WHAT DO I NEED TO DO HERE TO ACTUALLY UPDATE THE ROW?
    > //IS THE ONLY WAY TO DO IT IS by getting individual column values and
    > //constructing SQL statement?

    Yes. This is precisely what you have to do. For a look at an article
    that builds an editable DataGrid, see:

    An Extensive Examination of the DataGrid Web Control: Part 6
    [url]http://aspnet.4guysfromrolla.com/articles/071002-1.aspx[/url]

    Happy Programming!

    --

    <shameless plug>
    For more information on the DataGrid, DataList, and Repeater controls,
    consider picking up a copy of my latest book:

    ASP.NET Data Web Controls
    [url]http://www.amazon.com/exec/obidos/ASIN/0672325012/4guysfromrollaco[/url]
    </shameless plug>

    Happy Programming!

    Scott Mitchell
    [email]mitchell@4guysfromrolla.com[/email]
    [url]http://www.4GuysFromRolla.com[/url]
    [url]http://www.ASPFAQs.com[/url]
    [url]http://www.ASPMessageboard.com[/url]

    * When you think ASP, think 4GuysFromRolla.com!




    Scott Mitchell [MVP] Guest

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139