Batch Update in GridView control, is it possible?

Discussion in 'ASP .Net' started by LearnMore.John@gmail.com, Jun 23, 2006.

  1. Guest

    Is it possible to update all the rows in a single postback using
    Gridview Control,

    regards
    John
     
    , Jun 23, 2006
    #1
    1. Advertising

  2. Jared Guest

    John

    I am assuming you already have template columns set up to enter the
    data into.

    For this example I am using a TextBox inside a template column called
    strDateOfClean.


    int intCount = GridMain.Rows.Count;

    int intIndex = 0;

    while (intIndex < intCount)
    {

    TextBox strDateOfClean =
    GridMain.Rows[intIndex].FindControl("strDateOfClean") as TextBox;


    //Then you can do what you need to here to save the
    //strDateOfClean, such as updating an SQL table. e.g. Adding it to an
    SQL string
    //and firing a command.
    //string strsql = "Update tblTest set strTest = '" +
    strDateOfClean.Text + "'";



    intIndex += 1;

    }


    Cheers

    Jared


    wrote:

    > Is it possible to update all the rows in a single postback using
    > Gridview Control,
    >
    > regards
    > John
     
    Jared, Jun 23, 2006
    #2
    1. Advertising

  3. Jared Guest

    Missed a couple of bits you might need...

    This code can be fired from a button or a row command, either will
    work.

    In the SQL string I missed out that you need to refernce a primary key,
    which needs to be stored in your GridView somewhere, e.g.

    string strsql = "Update tblTest set strTest = '" + strDateOfClean.Text
    + "' where ID = " + GridMain.Rows[intIndex].Cells[0].Text;

    Hope this is useful

    Jared



    Jared wrote:

    > John
    >
    > I am assuming you already have template columns set up to enter the
    > data into.
    >
    > For this example I am using a TextBox inside a template column called
    > strDateOfClean.



    >
    >
    > int intCount = GridMain.Rows.Count;
    >
    > int intIndex = 0;
    >
    > while (intIndex < intCount)
    > {
    >
    > TextBox strDateOfClean =
    > GridMain.Rows[intIndex].FindControl("strDateOfClean") as TextBox;
    >
    >
    > //Then you can do what you need to here to save the
    > //strDateOfClean, such as updating an SQL table. e.g. Adding it to an
    > SQL string
    > //and firing a command.
    > //string strsql = "Update tblTest set strTest = '" +
    > strDateOfClean.Text + "'";
    >
    >
    >
    > intIndex += 1;
    >
    > }
    >
    >
    > Cheers
    >
    > Jared
    >
    >
    > wrote:
    >
    > > Is it possible to update all the rows in a single postback using
    > > Gridview Control,
    > >
    > > regards
    > > John
     
    Jared, Jun 23, 2006
    #3
    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. Edward
    Replies:
    1
    Views:
    328
    =?Utf-8?B?UmF2aW5kcmE=?=
    Jun 10, 2004
  2. ML
    Replies:
    1
    Views:
    872
  3. andy6
    Replies:
    2
    Views:
    553
    andy6 via DotNetMonster.com
    Jun 15, 2006
  4. rockdale

    Batch update in gridview?

    rockdale, Sep 12, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,990
    rockdale
    Sep 12, 2006
  5. rockdale

    Batch (NON inline ) update of gridview?

    rockdale, Sep 12, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    418
    rockdale
    Sep 12, 2006
Loading...

Share This Page