我想做个删除确认,可是都没弹出确认就把数据删除了代码如下:
if(e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
{ e.Item.Attributes.Add("onClick","JavaScript:return confirm('确定删除?')");
string intProductID;
string strSql;
SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
intProductID = dgrdProducts.DataKeys[e.Item.ItemIndex].ToString();
strSql = "Delete AssocReport Where Report_Id=@ProductID";
SqlCommand cmdSql = new SqlCommand( strSql, conn );
cmdSql.Parameters.Add( "@ProductID", intProductID );
conn.Open();
cmdSql.ExecuteNonQuery();
conn.Close();
dgrdProducts.EditItemIndex = -1;
BindDataGrid();
}
if(e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
{ e.Item.Attributes.Add("onClick","JavaScript:return confirm('确定删除?')");
string intProductID;
string strSql;
SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
intProductID = dgrdProducts.DataKeys[e.Item.ItemIndex].ToString();
strSql = "Delete AssocReport Where Report_Id=@ProductID";
SqlCommand cmdSql = new SqlCommand( strSql, conn );
cmdSql.Parameters.Add( "@ProductID", intProductID );
conn.Open();
cmdSql.ExecuteNonQuery();
conn.Close();
dgrdProducts.EditItemIndex = -1;
BindDataGrid();
}
解决方案 »
- 转ORACLE语句
- 微信自动回复,不知道哪个高手做过,回复语句数据库该怎么设计。有没有现成的解决方案。
- 求一.net源码,可换肤,有关注,相册功能,我能找到的源码太复杂,TKS,谢大家
- 做个网站后,如何在另一台没有VS的电脑上运行此网站?在线等,TKS!
- datalist的checkbox选中问题
- 模板列编辑
- 如何为网页动态指定样式表?
- 关于给DataList中的Label赋值的问题?
- 一个一直没解决的问题;关于弹出窗口的;
- 是深圳的VB程序员请进来灌水
- 共有3级类别,想在一个DropDownlist中显示第二级和第三级,但是不显示有第三级分类的第二级目录。
- web.config中如何使用响对路径
http://dotnet.aspx.cc/ShowList.aspx?id=1
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
LinkButton button = (LinkButton) e.Item.FindControl("LinkButton1");
if(button !=null)
button.Attributes.Add ("onclick","return confirm (\"确定要删除此项记录吗?\");");
}
}
你可能还有件事情没有做,那就是把这个删除列转化为模版列,我原来也是这样的.好象一转为模版列就可以了.另外,还要看你把上面的代码添加到ItemDataBound事件中没有.
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.EditItem Then
Dim but As LinkButton = CType(e.Item.Cells(3).Controls(0), LinkButton)
but.Attributes.Add("onclick", "return confirm('您确定要删除吗?')")
End If
End Sub
{
if(this.EmpRightCode == 4)
{
int index = e.Item.ItemIndex;
int depID = (int)dgdDep.DataKeys[index];
try
{
if((new DepSystem()).DeleteDep(depID))
{
this.WriteOptLog("删除部门"+depID.ToString()+"信息");
JScript.Alert("删除部门操作成功!");
}
else
{
JScript.Alert("删除部门操作失败!");
return;
}
}
catch
{
JScript.Alert("存在于此部门相关联的信息,不能删除!");
return;
}
dgdDep.DataBind();
}
else
JScript.Alert("您没有权限进行此操作!");
} private void dgdDep_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#fff7ce';cursor='hand';" ;
if (itemType == ListItemType.Item )
{
e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#dedfde';";
}
else if( itemType == ListItemType.AlternatingItem)
{
e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#ffffff';";
}
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
ImageButton button = (ImageButton) e.Item.FindControl("Imagebutton2");
button.Attributes.Add ("onclick",
"return confirm (\"确定要删除此项记录吗?\");");
}
}
并且在DataGrid_ItemCreated()中加入btnDelete.Attributes.Add("onClick", "jscript:if(!confirm('确认删除所选调查问题吗?')) return false;");btnDelete.Click += new EventHandler(Button1_Click);然后在该方法中执行,这样行不行呢?
这句放到ItemDataBound中
删除的语句放到DeleteCommand 中,然后关联事件就可以了
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.Cells[3].Attributes.Add("onclick","return confirm('您真的要删除此行吗?');");
} //第二种方法
<asp:ButtonColumn Text="<div onclick="return confirm('确实删除该留言吗?')">删除</div>"
HeaderText="删除" CommandName="Delete">
{
e.Item.Cells[6].Attributes.Add("onclick","return confirm('您真的要删除此用户吗?');");
}
在Cells[6].里的6是表示你的删除在单元格的第几位.
private void dgPerson_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//为删除操作添加一个确认属性
LinkButton delBttn = (LinkButton)e.Item.Cells[5].Controls[0];
delBttn.Attributes.Add("onclick","return confirm('确定要删除此项记录吗?');");
}
}