<asp:GridView ID="GridView1" runat="server" SkinID="gridviewSkinA" OnRowDataBound="GridView1_RowDataBound"
OnSelectedIndexChanging="GridView1_SelectedIndexChanging" OnRowDeleting="GridView1_RowDeleting">
<Columns>
<asp:CommandField SelectText="查看详细" ShowSelectButton="True" />
<asp:BoundField DataField="workername" HeaderText="经手人" />
<asp:BoundField DataField="work_date" HeaderText="日期" DataFormatString="{0:yyyy-MM-dd}"
HtmlEncode="False" />
<asp:BoundField DataField="work_time" HeaderText="时间" DataFormatString="{0:HH:mm}"
HtmlEncode="False">
<ItemStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="work_type" HeaderText="工作类型">
<ItemStyle Width="60px" />
</asp:BoundField>
<asp:BoundField DataField="subject" HeaderText="主题">
<ItemStyle Width="120px" />
</asp:BoundField>
<asp:BoundField DataField="content" HeaderText="内容">
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="re" HeaderText="备注">
<ItemStyle Width="120px" />
</asp:BoundField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick="javascript:return confirm('确认要删除吗?')" Text="删除"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我明明已经取消了,还是会删除项的。
求救中...
OnSelectedIndexChanging="GridView1_SelectedIndexChanging" OnRowDeleting="GridView1_RowDeleting">
<Columns>
<asp:CommandField SelectText="查看详细" ShowSelectButton="True" />
<asp:BoundField DataField="workername" HeaderText="经手人" />
<asp:BoundField DataField="work_date" HeaderText="日期" DataFormatString="{0:yyyy-MM-dd}"
HtmlEncode="False" />
<asp:BoundField DataField="work_time" HeaderText="时间" DataFormatString="{0:HH:mm}"
HtmlEncode="False">
<ItemStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="work_type" HeaderText="工作类型">
<ItemStyle Width="60px" />
</asp:BoundField>
<asp:BoundField DataField="subject" HeaderText="主题">
<ItemStyle Width="120px" />
</asp:BoundField>
<asp:BoundField DataField="content" HeaderText="内容">
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="re" HeaderText="备注">
<ItemStyle Width="120px" />
</asp:BoundField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick="javascript:return confirm('确认要删除吗?')" Text="删除"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我明明已经取消了,还是会删除项的。
求救中...
OnClientClick="return confirm('确认要删除吗?');"
这样呢
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="Delete"
OnClientClick='if(confirm("是否删除该条记录?")) return true ;else return false ;' Text="删 除" />
</ItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbtnDel" runat="server" CommandName="Delete" OnClientClick="return confirm('确认要删除吗?');" CausesValidation="False">删除</asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
<FooterStyle HorizontalAlign="Center" />
</asp:TemplateField>
------
顶,跟我的写法一样啊,不知道为什么了
因为你执行的是 deleting 事件
然后你在linkbutton上绑定的 脚本 所以它两个都执行的那么你就得把 删除的代码写在 按钮中就可以了
那么 你就把 前台的代码改成<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName=‘<%Eval("ID")%>’ OnClientClick="javascript:return confirm('确认要删除吗?')" Text="删除">然后后台 就在linkbutton的事件中写,获取ID
string ID=((LinkButton)sender).CommandName.ToString();然后再根据ID 删除就ok了
不过,我通常写作
OnClientClick="return confirm('确认要删除吗?');"
OnRowDeleting="GridView1_RowDeleting" 这个事件改成 OnRowCommand="GridView_Project_RowCommand" 后台:
if (e.CommandName.ToString() == "Delete_F")
{
DataTable dt = new DataTable();
string ProjectId = e.CommandArgument.ToString();
dt = bf.CheckThisGczzt(ProjectId);
//判断该工程是否有审计工程
if (dt.Rows.Count == 0)
{
try
{
DataTable dt1 = new DataTable();
dt1 = bfUnitProject.CheckProjectId(ProjectId);
if (dt1 != null && dt1.Rows.Count > 0)
{
if (int.Parse(dt1.Rows[0]["IsexistPro"].ToString()) == 0)
{
bf.DeleteProject(ProjectId);
}
else
{
Response.Write("<script >alert('该工程存在与某个评审流程之中!');</script>");
}
}
else
{
Response.Write("<script >alert('删除失败!');</script>");
}
}
catch
{ }
}
else
{
Response.Write("<script language='javascript'>alert('存在该工程的审计工程!');</script>");
}
BindData(); }
看中间:
临时文件下有
删除Cookie 删除文件 设定
点中间的删除文件就是删除缓存了(由于我的系统不是中文的,所以都是翻译后的,不见得一模一样,意思应该没错)
其实这样是肯定不会错的,以前我也是这样写的,但是在我的这个里面就老是会出错。
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick="javascript:return confirm('确认要删除吗?')" Text="删除"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
界面增加一个事件:OnRowCreated="GridView1_RowCreated"<asp:GridView ID="GridView1" runat="server" SkinID="gridviewSkinA" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanging="GridView1_SelectedIndexChanging"
OnRowDeleting="GridView1_RowDeleting"
OnRowCreated="GridView1_RowCreated" > 后台代码:protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton btnDel = (LinkButton)e.Row.Cells[8].Controls[0];
btnDel.Attributes.Add("onclick", "return confirm('确认要删除吗?');");
}
}
原来界面的OnClientClick事件就不用了