不能删除数据,请高手指点

zp1314 2008-09-15 07:39:54
1 aspx.cs源代码:
namespace qminoa.Webs.HR
{
/// <summary>
/// hrjtInf 的摘要说明。
/// </summary>
public class hrjtInf : qminoa.Webs.PageBase
{
protected System.Web.UI.WebControls.HyperLink AddhrjtLink;
protected System.Web.UI.WebControls.DataGrid dgdhrjt;
protected System.Web.UI.WebControls.Label lblError;

private void Page_Load(object sender, System.EventArgs e)
{
this.PageBegin("家庭信息",true);
if(this.EmpRightCode >= 2)
AddhrjtLink.NavigateUrl="./hrjtNew.aspx";
DataBind();
}

public DataTable hrjtTB
{
get
{
return (new hrJtSystem()).GetHrjt(Session["emp_no"].ToString());
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dgdhrjt.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgdhrjt_PageIndexChanged);
this.dgdhrjt.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgdhrjt_DeleteCommand);
this.dgdhrjt.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgdhrjt_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void dgdhrjt_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//if(this.EmpRightCode == 4)
//{
int index = Convert.ToInt32(e.Item.Cells[0].Text,10);//e.Item.ItemIndex;
int id = Convert.ToInt16(dgdhrjt.DataKeys[index].ToString(),10);
bool result = (new hrJtSystem()).DeleteHrjt(id);
dgdhrjt.DataBind();
//}
//else
// JScript.Alert("您没有权限进行此操作!");
}

private void dgdhrjt_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgdhrjt.CurrentPageIndex = e.NewPageIndex;
dgdhrjt.DataBind();
}

private void dgdhrjt_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 (\"确定要删除此项记录吗?\");");
}
}
}
}
2 aspx的代码
<%@ Page language="c#" Codebehind="hrjtInf.aspx.cs" AutoEventWireup="false" Inherits="qminoa.Webs.HR.hrjtInf" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title></title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="../lynn.css" type="text/css" rel="stylesheet">
</HEAD>
<body bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<TABLE style="POSITION: absolute" height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
<TR>
<TD style="HEIGHT: 27px">
<TABLE class="headcenter" style="WIDTH: 100%; HEIGHT: 18px" cellSpacing="1" cellPadding="1" width="100%" border="0">
<TR>
<TD align="left" style="WIDTH: 469px"> 家庭信息
</TD>
<TD noWrap align="right"></TD>
</TR>
</TABLE>
 
</TD>
</TR>
<TR>
<TD vAlign="top" align="middle">
<TABLE width="499" cellSpacing="0" cellPadding="0" bordercolordark="#ffffff" bordercolor="#888888" border="1">
<TR>
<TD style="WIDTH: 100%; HEIGHT: 14px" vAlign="top"><TABLE style="WIDTH: 100%; HEIGHT: 20px" cellSpacing="0" cellPadding="0" width="100%" border="0">
<TR>
<TD style="WIDTH: 413px">信息列表
</TD>
<TD class="td" noWrap align="right"></TD>
<TD class="td" noWrap width="80">
<asp:HyperLink id="AddhrjtLink" runat="server" Font-Size="X-Small"><img src="../img/add.gif" border="0" align="absbottom"> 新增</asp:HyperLink></TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD style="WIDTH: 100%; HEIGHT: 155px" vAlign="top">
<ASP:DATAGRID id=dgdhrjt runat="server" DataKeyField="id" Font-Names="Verdana" BorderWidth="1px" BackColor="#F7F7F7" BorderColor="#F7F7F7" CssClass="table" BorderStyle="Solid" width="717px" AutoGenerateColumns="False" HeaderStyle-font-weight="fold" HeaderStyle-BackColor="#d8c8a8" Font-Name="Verdana" CellPadding="3" Height="81px" DataSource="<%# hrjtTB %>" AllowPaging="True" PageSize="8" >
<SelectedItemStyle BackColor="Transparent"></SelectedItemStyle>
<EditItemStyle ForeColor="Black" BackColor="Black"></EditItemStyle>
<AlternatingItemStyle BorderColor="White" BackColor="White"></AlternatingItemStyle>
<ItemStyle CssClass="textcenter" BackColor="#DEDFDE"></ItemStyle>
<HeaderStyle CssClass="headcenter" BackColor="#D8C8A8"></HeaderStyle>
<FooterStyle Font-Size="X-Small" CssClass="headcenter"></FooterStyle>
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="id" DataNavigateUrlFormatString="./hrjtUp.aspx?id={0}" DataTextField="inf_type_name" HeaderText="成员类型">
<ItemStyle Wrap="False"></ItemStyle>
</asp:HyperLinkColumn>
<asp:BoundColumn DataField="name" HeaderText="姓/名">
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="sex_name" HeaderText="性别">
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="birth" HeaderText="出生日期">
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="company" HeaderText="工作单位">
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="communi" HeaderText="联系方式">
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="删除">
<ItemStyle Width="10%"></ItemStyle>
<ItemTemplate>
<asp:ImageButton CausesValidation="False" id="Imagebutton2" runat="server" ImageUrl="../img/delete.gif" CommandName="delete" AlternateText="删除当前部门"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Mode="NumericPages"></PagerStyle>
</ASP:DATAGRID></TD>
</TR>
<TR>
<TD style="WIDTH: 611px"><asp:label id="lblError" runat="server" CssClass="err" Visible="False" Font-Size="X-Small"></asp:label></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</FONT>
</form>
</body>
</HTML>
...全文
99 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zp1314 2008-09-16
  • 打赏
  • 举报
回复
<asp:TemplateColumn HeaderText="删除">
<ItemStyle Width="10%"> </ItemStyle>
<ItemTemplate>
<asp:ImageButton CausesValidation="False" id="Imagebutton2" runat="server" ImageUrl="../img/delete.gif" CommandName="delete" AlternateText="删除当前部门"> </asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>


真是我从别的地方拷贝来的,这个按钮执行删除,但不知道为什么能删除
满衣兄 2008-09-16
  • 打赏
  • 举报
回复
the button not be register,please register. or delete the button and creat a new.
zp1314 2008-09-16
  • 打赏
  • 举报
回复
错误是:点删除没有反应,不执行删除操作,我用的是存储过程,不是过程的问题;
我把id手工赋值为1 ,但是也不能删除数据,我觉得dgdhrjt_DeleteCommand好像没有执行啊,我也不会调配,真是急死了要。
toxxj 2008-09-15
  • 打赏
  • 举报
回复
设断点调试看下面的代码是否取到了正确的id:
int index = Convert.ToInt32(e.Item.Cells[0].Text,10);
int id = Convert.ToInt16(dgdhrjt.DataKeys[index].ToString(),10);
bool result = (new hrJtSystem()).DeleteHrjt(id);

如果id正确的话,再去检查你的删除代码是否正确
chenglidexiaoxue 2008-09-15
  • 打赏
  • 举报
回复
什么错误?影响零行么?
shadowjl 2008-09-15
  • 打赏
  • 举报
回复
看得头晕.把关键的弄出来~
yuelailiu 2008-09-15
  • 打赏
  • 举报
回复
1 查看事务是否执行
2 外键关联
gui0605 2008-09-15
  • 打赏
  • 举报
回复
代码太乱,懒得看

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧