DataList、GridView、dataGridView、中判断提示是否删除一行记录代码

来源:互联网 发布:c游戏编程入门 编辑:程序博客网 时间:2024/05/16 16:11

 第一  DataList中判断提示是否删除一行记录代码

 

  前台代码(.aspx页面js代码)

  <script language="javascript">
        function isdel()
        {
            if(window.confirm('请确认删除'))
            {
                document.all.isDel.value = "true"
                frmDel.submit();//到服务端去删除
            }
            else
            return false;
        }
    </script>

 

然后在DataList的模板列里的删除按钮是加入

 <asp:LinkButton ID="LinkButton1" runat="server" CommandName="delete"

OnClientClick="return isdel();">删 除</asp:LinkButton>

 

 第二 GridView中判断提示是否删除一行记录代码

 

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowIndex != -1)
        {
            if (e.Row.RowState == DataControlRowState.Alternate || e.Row.RowState == DataControlRowState.Normal)
            {
                LinkButton lb = e.Row.Cells[2].Controls[0] as LinkButton;
                lb.Attributes.Add("onclick", "javascript:return confirm('确定要删除吗?')");
            }
            else
            { }
        }
    }

 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int bm_id = int.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString());//获取设置GridView的主键
        if (BLL.BarInfo.DeleteMainBar(bm_id))
        {
            Bind();//重新绑定一次Gridview数据
        }
        else
        {
            JScript.Alert("删除失败!");
        }
    }

 

 第三  dataGridView中判断提示是否删除一行记录代码


 int rowindex = this.dataGridView1.CurrentRow.Index;//获取主键
 string code = this.dataGridView1[0, rowindex].Value.ToString();//删除的条件,可以自定义
 DialogResult dr = MessageBox.Show("你确定要删除选中的行吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (dr == DialogResult.Yes)
                {
                    bool bl = BLL.TeacherBLL.DeleteStudent(code);
                    if (bl)
                    {
                        MessageBox.Show("删除成功!");
                        bind1();
                    }
                    else
                    { MessageBox.Show("删除失败!"); }
                }

 

原创粉丝点击