Batch Update in GridView control, is it possible?

L

LearnMore.John

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

regards
John
 
J

Jared

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
 
J

Jared

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


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


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

regards
John
 

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,767
Messages
2,569,573
Members
45,046
Latest member
Gavizuho

Latest Threads

Top