Delete multiple rows on button click

Oct 20 2006 2:07 AM
Hi,

I have created selectall checkbox(item template) in the datagrid and want to delete one or more rows depending on if the user clicks on individual checkbox or selectall checkbox.

My logic is  : delete from table where id=@ id   (for one row) or

delete from table where id IN(1,2)      (multiple rows)


If selectall checkbox is checked, all the rows in the particular page will be selected.

But I am not getting the correct syntax to delete the rows.

The code I have written is:



protected void btndelete_Click(object sender, EventArgs e)

{

foreach (DataGridItem dgi in MyDataGrid.Items)

{

CheckBox checkall;

checkall = (CheckBox)dgi.FindControl("chkselect");

string topicid = MyDataGrid.DataKeys[dgi.ItemIndex].ToString();

if (checkall.Checked==true)

{

 string delrecord="delete from Admin_Add_Newsletter_Topic where Topic_Id=" & topicid;

SqlConnection con=new SqlConnection(ConnectionString);

SqlCommand cmd=new SqlCommand(delrecord, con);

con.Open();

cmd.ExecuteNonQuery();

con.Close();

}

}

}


But I receive the following error:


Error 1 Operator '&' cannot be applied to operands of type 'string' and 'string'






Answers (2)