Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
Delete multiple rows on button click
Sandhya Bhosale
Oct 20 2006 2:07 AM
2.1k
Reply
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'
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
newbie on C#.net
Use component MODI of microsoft! Help me!