在asp.net 中,利用datagrid控件添加删除按钮,期望结果是:点击删除按钮,如果删除的记录下有子记录,就弹出一个对话框,提示不能删除,同时不让页面刷新,但实际操作中,发现对话框弹出是没有问题,但一弹出对话框,页面马上变成了空白,什么都看不到了,我想让页面保持原来的样子,各位高手,说说可不可以实现啊,有人建议在页面上加上:smartNavigation=true ,我加上后,页面是没有刷新,但对话框确不显示了,有什么好办法解决吗?在线等待。谢谢各位支持啊!
调试欢乐多
或者你也可以把记录下有子记录的标志一开始也取到客户端,
再用javascript判断也可以做到不刷新
Public Function MsgBoxShowOK(ByVal MsgString As String) As ClientScriptManager
Dim csm As ClientScriptManager = Page.ClientScript
Dim csmType As Type = Me.GetType()
Dim csmKey As String = "ButtonClickScript"
Dim csmString As String = "alert('" & MsgString & "');"
csm.RegisterStartupScript(csmType, csmKey, csmString, True)
Return csm
End Function 使用的时候:
Dim msg As ClientScriptManager=MsgBoxShowOK("不能删除")
你可以在MSDN上输入 ClientScriptManager搜索下相关C#用法
string str_bh = e.Item.Cells[0].Text.Trim();//获得删除记录的编号。
int lastindex=0;
string zzbh="01";//组织编号,暂以“01”代替
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionSqlServer"]);//连接数据库
string str_sql = "SELECT khzycdflbh from biz_jxcclientrecord where khzycdflbh='"+ str_bh +"' and zzbh = '"+ zzbh + "'";
myCommand = new SqlCommand(str_sql,conn);
SqlDataAdapter Adapter = new SqlDataAdapter();
Adapter.SelectCommand = myCommand;
DataSet ds = new DataSet();
Adapter.Fill(ds,"kh");
conn.Close();
int int_num = ds.Tables["kh"].Rows.Count;
ds.Clear();
if(int_num > 0)//如果客户表(biz_jxcclientrecord)下有此类别的用户在,不能删除此类别
Response.Write("<script language=javascript>alert('此类别还有用户存在,当前不能删除!')</script>");
else
{
try
{
str_sql = "delete from biz_jxcclienttype_importance where khzycdflbh = '"+str_bh+"' and zzbh = '"+zzbh+"'";
myCommand.CommandText = str_sql;
myCommand.Connection = conn;
conn.Open();
myCommand.ExecuteNonQuery();
lastindex=dg_khlb.CurrentPageIndex;
if(dg_khlb.PageCount-lastindex==1&&dg_khlb.Items.Count==1)//dg_khlb是datagrid控件名
{
if(dg_khlb.PageCount>1)
lastindex=lastindex-1;
else
lastindex=0;
dg_khlb.CurrentPageIndex=lastindex;
}
}
catch(Exception err)
{
Response.Write("<script language=javascript>alert('"+err.Message.ToString()+"')</script>");
}
finally
{
conn.Close();
jxcDataBind();//datagrid重新进行绑定
}