事件冒泡 [英] Event Bubbling

查看:85
本文介绍了事件冒泡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
  {
    if (e.CommandName == "Edit")
    { 
      Response.Redirect("~/Form1.aspx?SrNo=" +  e.CommandArgument.ToString());
    }
    else if (e.CommandName == "Delete")
    {
      SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConn"].ToString());
      con.Open();
      SqlCommand cmd = new SqlCommand();
      cmd.CommandText = "Delete from Rnd Where SrNo =" + e.CommandArgument.ToString();
      cmd.Connection = con;
      if (cmd.ExecuteNonQuery() > 0)
      {
        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Message", "alert('Record deleted');window.location.href='Form2.aspx';", true);
      }
      else
      {
        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Message", "alert('Record not deleted')", true);
      }
    }
  }



[edit]添加了代码块以保留格式-OriginalGriff [/edit]



[edit]Code block added to preserve formatting - OriginalGriff[/edit]

推荐答案

不,这根本不是事件冒泡的代码.

建议您先阅读,然后尝试,然后在遇到问题时发布特定问题. :thumbsup:
No, this is not at all the code of event bubbling.

Would suggest you to read first, then try and then post specific issue if faced. :thumbsup:


没有问题,并从标题中删除了((是对的))".我们无法告诉您您的代码是否正确",因为我们没有(也不想要)您的所有代码.如果可以编译,请在调试器下运行它.如果不正确,您很快就会知道.
Not a question, and removed "(Is it right)" from title. We can''t tell you if your code is "right", because we don''t have (nor do we want) all of your code. If it compiles, run it under the debugger. If it''s not right, you''ll know in short order.


这篇关于事件冒泡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆