ASP.NET C# 弹出对话框提示信息点击确定不跳转页面(仍留在网页)
弹出对话框提示信息点击确定不跳转页面(仍留在网页)如何设置button和gridview里面的删除commandfield是够是相同做法?...
弹出对话框提示信息 点击确定不跳转页面(仍留在网页)如何设置
button和gridview里面的删除commandfield是够是相同做法? 展开
button和gridview里面的删除commandfield是够是相同做法? 展开
2个回答
展开全部
我用的是LinkButton你可以参考一下,希望对你有用
前台代码:提示信息
<asp:LinkButton CommandName="del" CommandArgument='<%#Eval("s_id") %>' ID="LinkButton2" runat="server" OnClientClick="if(window.confirm('你确定要删除!')){ return true;}else{return false;}">删除</asp:LinkButton>
后台代码:
public int insertOrUpdate(string sql) {
int eccf = -1;
SqlConnection conn = db.open();
try
{
SqlCommand cmd = new SqlCommand(sql,conn);
eccf=cmd.ExecuteNonQuery();
return eccf;
}
finally
{
db.close();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "del")
{
string sql = "delete from 表名 where 字段=" + e.CommandArgument;
if (ex.insertOrUpdate(sql) != -1)
{
SqlConnection strconn = new SqlConnection();
strconn.Open();
SqlDataAdapter dr = new SqlDataAdapter("select * from 表名", strconn);
DataSet ds = new DataSet();
dr.Fill(ds);
GridView1.DataSource = ds.Tables[" 表名"];
GridView1.DataBind();
strconn.Close();
}
else
{
Response.Write("<script>alert('删除失败!');window.location.href='testList.aspx';</script>");
}
}
}
}
前台代码:提示信息
<asp:LinkButton CommandName="del" CommandArgument='<%#Eval("s_id") %>' ID="LinkButton2" runat="server" OnClientClick="if(window.confirm('你确定要删除!')){ return true;}else{return false;}">删除</asp:LinkButton>
后台代码:
public int insertOrUpdate(string sql) {
int eccf = -1;
SqlConnection conn = db.open();
try
{
SqlCommand cmd = new SqlCommand(sql,conn);
eccf=cmd.ExecuteNonQuery();
return eccf;
}
finally
{
db.close();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "del")
{
string sql = "delete from 表名 where 字段=" + e.CommandArgument;
if (ex.insertOrUpdate(sql) != -1)
{
SqlConnection strconn = new SqlConnection();
strconn.Open();
SqlDataAdapter dr = new SqlDataAdapter("select * from 表名", strconn);
DataSet ds = new DataSet();
dr.Fill(ds);
GridView1.DataSource = ds.Tables[" 表名"];
GridView1.DataBind();
strconn.Close();
}
else
{
Response.Write("<script>alert('删除失败!');window.location.href='testList.aspx';</script>");
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询