Reputation: 442
I use girdview. and for deleting I use LinkButton in each row.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
((LinkButton)e.Row.Cells[12].Controls[0]).Attributes.Add("onClick",
"return false;"
);
}
}
Now, I would expect nothing to happen when I Link Button
is clicked because OnClick
returns false
. Right?
BUT
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName=="SIL")
{
String _id = GridView1.DataKeys[Int32.Parse(e.CommandArgument.ToString())].Values["id"].ToString();
dsodeme_onkayitTableAdapters.odeme_onkayitTableAdapter _todeme = new dsodeme_onkayitTableAdapters.odeme_onkayitTableAdapter();
_todeme.DeleteQueryID(_id);
Response.Redirect("musteri_onkayit_odeme_al.aspx?username=" + lbUserName.Text);
}
}
is being invoked. The RowCommand
is running and deleting the records.
Please help me find the problem. I use Vista Home Premium and IE8. Is that the problem?
Upvotes: 0
Views: 1703
Reputation: 442
Ok, I fix it like this;
attribute.add ("onClick","if(!confirm('Are you sure?')) event.returnValue=false;");
it's works. Thanks.
Upvotes: 1
Reputation: 572
Instead of:
((LinkButton)e.Row.Cells[12].Controls[0]).Attributes.Add("onClick",
"return false;"
);
Try:
((LinkButton)e.Row.Cells[12].Controls[0]).OnClientClick = "return false;";
Upvotes: 1
Reputation: 8653
I know this may not sound like the answer you want but if you know that control should not allow a deletion why not just make it invisible i.e. Hide the control.
In the end this will achieve what you are trying to do.
Upvotes: 0
Reputation: 1473
I think Jan must be on to something, is it possible that the actual link you try to add the onClick on is not 'cell 12 control 0' ?
You should show the output and we'll be able to figure out what's wrong.
Upvotes: 0