السلام عليكم ورحمة الله وبركاته ..
أخواني الكرام لدي GridView ووضعت GirdView تأخذ قيمة الحقل Active من قاعدة البيانات من نوع Bit .. وضعت زر في الأسفل بحيث لما اغير في القيم بحيث أضع علامة (صح) وأضغط الزر فإنه يقوم بتحديث السجلات كلها !.
للأسف عندما أنقر على الزر فانه يعمل بوست باك ويعيد السجلات الى نفس القيم القديمة بدون أي تعديل !! مالخطأ في الكود بارك الله فيكم ..
string connectionString;
SqlCommand command;
public string ConnectionString
{
get { return connectionString; }
set { connectionString = value; }
}
protected void Button1_Click(object sender, EventArgs e)
{
ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection MyConnection = new SqlConnection(ConnectionString);
//Open the Connection to the Sql Server
MyConnection.Open();
foreach (GridViewRow row in GridView1.Rows)
if (row.RowType == DataControlRowType.DataRow)
{
int active = 0;
if (((CheckBox)row.FindControl("CheckBox2")).Checked)
active = 1;
else
active = 0;
command = new SqlCommand();
command.Connection = MyConnection;
command.CommandText = "update News set Active=" + active.ToString() + " where Id=" + GridView1.DataKeys[row.RowIndex].Value.ToString();
command.ExecuteNonQuery();
}
MyConnection.Close();
}

