سمیرا55
پنج شنبه 13 تیر 1392, 21:20 عصر
سلام
یک gridview دارم که داخلش دکمه ویرایش گذاشتم کد زیرو داخل رویداد کلیک دکمه نوشتم آپدیت میکنه ولی همه سطرها رو یک جور update میکنه فک میکنم به خاطر این که همه دستورات رو داخل حلقه نوشتم خواهش میکنم راهنمایی بفرمایید
protected void ImageButton4_Click(object sender, ImageClickEventArgs e)
{
foreach (GridViewRow rowItem in GridView1.Rows)
{
Int32 ID1 = 0;
ID1 = Convert.ToInt32(((sender as ImageButton).Parent.FindControl("HiddenField2") as HiddenField).Value);
TextBox chk1 = (TextBox)(rowItem.Cells[0].FindControl("TextBox1"));
SqlConnection co1 = new SqlConnection();
co1.ConnectionString = "Data Source=.;Initial Catalog=sms_website;Integrated Security=True";
co1.Open();
string qry1 = "update goru set group_name='" + chk1.Text + "' where goru.id='" + ID1 + "'";
SqlCommand cmd1 = new SqlCommand(qry1, co1);
cmd1.ExecuteNonQuery();
co1.Close();
Response.Redirect("groups.aspx");
}
}
یک gridview دارم که داخلش دکمه ویرایش گذاشتم کد زیرو داخل رویداد کلیک دکمه نوشتم آپدیت میکنه ولی همه سطرها رو یک جور update میکنه فک میکنم به خاطر این که همه دستورات رو داخل حلقه نوشتم خواهش میکنم راهنمایی بفرمایید
protected void ImageButton4_Click(object sender, ImageClickEventArgs e)
{
foreach (GridViewRow rowItem in GridView1.Rows)
{
Int32 ID1 = 0;
ID1 = Convert.ToInt32(((sender as ImageButton).Parent.FindControl("HiddenField2") as HiddenField).Value);
TextBox chk1 = (TextBox)(rowItem.Cells[0].FindControl("TextBox1"));
SqlConnection co1 = new SqlConnection();
co1.ConnectionString = "Data Source=.;Initial Catalog=sms_website;Integrated Security=True";
co1.Open();
string qry1 = "update goru set group_name='" + chk1.Text + "' where goru.id='" + ID1 + "'";
SqlCommand cmd1 = new SqlCommand(qry1, co1);
cmd1.ExecuteNonQuery();
co1.Close();
Response.Redirect("groups.aspx");
}
}