<asp:TemplateField HeaderText="Posta">
<ItemTemplate>
<asp:CheckBox ID="P" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ajanda">
<ItemTemplate>
<asp:CheckBox ID="E" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
foreach (GridViewRow satir in GridView1.Rows) //her satir için bir döngü
{
CheckBox kutuP = satir.FindControl("P") as CheckBox; //mevcut satirdaki
CheckBox kutuE = satir.FindControl("E") as CheckBox; //mevcut satirdaki
//Checkbox'i oku
if (kutuP.Checked == true) //eger kutu isaretlenmisse
{ //Mevcut satira ait anahtar degeri bul.(Unique deger bizde ID)
int idP = Convert.ToInt32(GridView1.DataKeys[satir.RowIndex].Value);
//AccessDataSource1.DeleteParameters["ID"].DefaultValue = id.ToString();
//AccessDataSource1.Delete(); //Ve satiri sil...
SqlCommand Pupdate = new SqlCommand();
Pupdate.Connection = serkan;
Pupdate.CommandText = String.Format(" UPDATE ADRES SET " + Label5.Text + " = 1 WHERE ID='" + idP + "'");
serkan.Open();
Pupdate.ExecuteNonQuery();
serkan.Close();
}
if (kutuP.Checked == false) //eger kutu isaretlenmisse
{ //Mevcut satira ait anahtar degeri bul.(Unique deger bizde ID)
int idP = Convert.ToInt32(GridView1.DataKeys[satir.RowIndex].Value);
//AccessDataSource1.DeleteParameters["ID"].DefaultValue = id.ToString();
//AccessDataSource1.Delete(); //Ve satiri sil...
SqlCommand Pupdate = new SqlCommand();
Pupdate.Connection = serkan;
Pupdate.CommandText = String.Format(" UPDATE ADRES SET " + Label5.Text + " = 0 WHERE ID='" + idP + "'");
serkan.Open();
Pupdate.ExecuteNonQuery();
serkan.Close();
}
if (kutuE.Checked == true) //eger kutu isaretlenmisse
{ //Mevcut satira ait anahtar degeri bul.(Unique deger bizde ID)
int idE = Convert.ToInt32(GridView1.DataKeys[satir.RowIndex].Value);
//AccessDataSource1.DeleteParameters["ID"].DefaultValue = id.ToString();
//AccessDataSource1.Delete(); //Ve satiri sil...
SqlCommand Eupdate = new SqlCommand();
Eupdate.Connection = serkan;
Eupdate.CommandText = String.Format(" UPDATE ADRES SET " + Label7.Text+ " = 1 WHERE ID='" + idE + "'");
serkan.Open();
Eupdate.ExecuteNonQuery();
serkan.Close();
}
if (kutuE.Checked == false) //eger kutu isaretlenmisse
{ //Mevcut satira ait anahtar degeri bul.(Unique deger bizde ID)
int idE = Convert.ToInt32(GridView1.DataKeys[satir.RowIndex].Value);
//AccessDataSource1.DeleteParameters["ID"].DefaultValue = id.ToString();
//AccessDataSource1.Delete(); //Ve satiri sil...
SqlCommand Eupdate = new SqlCommand();
Eupdate.Connection = serkan;
Eupdate.CommandText = String.Format(" UPDATE ADRES SET " + Label7.Text + " = 0 WHERE ID='" + idE + "'");
serkan.Open();
Eupdate.ExecuteNonQuery();
serkan.Close();
}
}
0 Comments