But how could you live and have no story to tell!
访问统计 original graphics

大家都知道GridView自带删除按钮在删除一条记录时不会有任何提示,那么改造后在删除GridView中的一条记录时弹出一个提示信息。
步骤如下:
       1.在GridView中添加一个模板列,然后编辑模板,添加一个LinkButton。

       2.在GridView_RowDataBound事件中添加代码:
          protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
         {
               ("LinkButton1")).Attributes.Add("onclick", "Javascript:return 
          confirm('这将彻底删除这条记录,你确定吗?');");
          }

       3.双击摸板中的LinkButton,在LinkButton_Click中添加删除代码:
         protected void LinkButton1_Click(object sender, EventArgs e)
        {
              SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStrings  ["ConnectionString"].ConnectionString);
              myconn.Open();
             string sql = "delete xxx where ID = " + ((LinkButton)sender).CommandArgument.ToString();
             SqlCommand mycmd = new SqlCommand(sql, myconn);
             mycmd.ExecuteNonQuery();
             myconn.Close();
             GridView1.DataSourceID = "SqlDataSource1";
             GridView1.DataBind();
        }

posted on 2007-06-06 18:07  nextsoft  阅读(569)  评论(0编辑  收藏  举报