TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sandhya Bhosale
NA
18
0
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'
Reply
Answers (
2
)
newbie on C#.net
Use component MODI of microsoft! Help me!