added checkbox on gridview this method:
<asp:TemplateField>
<
ItemTemplate>
<
asp:CheckBox runat="server" ID="CheckBox1" />
</
ItemTemplate>
I want to save selected values another table but I did not achive.First I try this code and then I will convert this delete statement to select statement ,it deletes checked value but there is sql exception ID =@ID and keyid=@keyid"; I think this values should be primary key,but I cant set primary key in a table both of them(keyid my primary key now I need this primary key when user select one row ).Please give idea,I tried most of things and tired:(
string connStr = ConfigurationManager.ConnectionStrings["bdConnectionString"].ConnectionString;
string sql = "Delete From ekleme Where ID =@ID and keyid=@keyid";
SqlConnection conn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.CommandType =
CommandType.Text;
SqlParameter keyid = cmd.Parameters.Add("@keyid", SqlDbType.Int);
SqlParameter ID = cmd.Parameters.Add("@ID", SqlDbType.Int);
keyid.Value = Session[
"keyid"];
string str = "";
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
bool isChecked =((CheckBox)row.FindControl("CheckBox1")).Checked;
if (isChecked)
{
str =
"Seçildi";
conn.Open();
ID.Value = GridView1.Rows[i].Cells[0].Text;
cmd.ExecuteNonQuery();
}
}
Response.Write(str);