views:

528

answers:

4

Hi, 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?

A: 

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.

SBUJOLD
A: 

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.

RC1140
Hi, When I run in Internet Explorer 8 , confirm does not works.BUT I select my project right click and I click Browse With... than I Select Internal Web Browser. IT IS VERY NICE WORK in Internal Web Browser. But IE8 does not works conrim? SO What is the problem?
atromgame
+1  A: 

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;";
ianpoley
I try it, but does not work again.
atromgame
A: 

Ok, I fix it like this;

attribute.add ("onClick","if(!confirm('Are you sure?')) event.returnValue=false;");

it's works. Thanks.

atromgame