Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My code as follows


protected void btnsubmit_Click(object sender, EventArgs e)
{
try
{
String strConnString = ConfigurationManager.ConnectionStrings["ConnectionStrings"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
con.Open();
foreach (GridViewRow row in grdRpt.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkselecdata");
if (cb.Checked == true)
{
int key = Convert.ToInt32(grdRpt.DataKeys[row.RowIndex].Value);
SqlCommand cmd = new SqlCommand("UPDATE [transact].[transaction_item] SET Status = 'Ready' Where transaction_id=" + key.ToString(), con);
cmd.ExecuteNonQuery();

}
}
con.Close();
}
catch (Exception ex)
{

}
}


in Gridview record as follows


selectdata ID Transacteedid Qty Price Status

Checkbox 1 12345 1 20 NEW
1 2 Paging in gridview

when i click 2 page in gridview below record will display
Chekbox 2 12345 2 30 NEW


i am selecting the gridview from page1 and page2 .

i am updating both record from page1 and page2 record from the gridview.

i have to one submit button called "Update".

when i update page2 record from the gridview only update in the database i am also selecting the record from page1 also.

But page1 record is not update in the database.

What is the mistake in my above code.

In update button i written for loop for the gridview. but it is not working.

What I have tried:

My code as follows


protected void btnsubmit_Click(object sender, EventArgs e)
{
try
{
String strConnString = ConfigurationManager.ConnectionStrings["ConnectionStrings"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
con.Open();
foreach (GridViewRow row in grdRpt.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkselecdata");
if (cb.Checked == true)
{
int key = Convert.ToInt32(grdRpt.DataKeys[row.RowIndex].Value);
SqlCommand cmd = new SqlCommand("UPDATE [transact].[transaction_item] SET Status = 'Ready' Where transaction_id=" + key.ToString(), con);
cmd.ExecuteNonQuery();

}
}
con.Close();
}
catch (Exception ex)
{

}
}


in Gridview record as follows


selectdata ID Transacteedid Qty Price Status

Checkbox 1 12345 1 20 NEW
1 2 Paging in gridview

when i click 2 page in gridview below record will display
Chekbox 2 12345 2 30 NEW


i am selecting the gridview from page1 and page2 .

i am updating both record from page1 and page2 record from the gridview.

i have to one submit button called "Update".

when i update page2 record from the gridview only update in the database i am also selecting the record from page1 also.

But page1 record is not update in the database.

What is the mistake in my above code.

In update button i written for loop for the gridview. but it is not working.
Posted
Comments
Paschga 19-Jun-18 8:10am    
Dude please tell me are you for real!?
I think Richard-MacCutchan is right, your problem is the general understanding of the C# language and the problem you are having... The Code you posted stays the same since at least 3 Posts, and in the what you tried section you simply copy your problem again, please acknowledge the rules of posting if you want to have serious help!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900