asp.net 删除问题??

zql2008 zql2008 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace person.datalist
{
/// <summary>
/// editnews 的摘要说明。
/// </summary>
public class editnews : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgnew;
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
this.datanew();
}
Server.Execute("judge.aspx");
// 在此处放置用户代码以初始化页
}

private void datanew()
{
SqlConnection con=DB.createConn();
SqlDataAdapter sda=new SqlDataAdapter("select * from news",con);
DataSet ds=new DataSet();
sda.Fill(ds,"news");
this.dgnew.DataKeyField="id";
this.dgnew.DataSource=ds.Tables["news"];
this.dgnew.DataBind();

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

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

}
#endregion

private void dgnew_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.dgnew.CurrentPageIndex=e.NewPageIndex;
this.datanew();
}

private void dgnew_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor='#eeeeff'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=c;");
// e.Item.Attributes.Add("onclick","return confirm('真得要删除吗?')");
((LinkButton)(e.Item.Cells[2].Controls[0])).Attributes.Add("onclick","return confirm('真得要删除吗?')");
}
}

private void dgnew_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string id=this.dgnew.DataKeys[e.Item.ItemIndex].ToString();
// Response.Write(id);
// Response.End();
SqlConnection con=DB.createConn();
SqlCommand cmd=new SqlCommand("delete from news where id='"+id+"'",con);
con.Open();
cmd.ExecuteNonQuery();
this.datanew();
}
}
}

上面是我用dbgrid 开始时是可以删除的, 最近不知道怎么删除不了,

没反应该的, 不知道那里出错

...全文

相关推荐

ASP.NET MVC 4使用PagedList.Mvc分页的实现代码

本篇文章主要介绍了ASP.NET MVC 4使用PagedList.Mvc分页的实现代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

weixin_38616435

asp.net, c#,gridview对数据进行绑定,增加,查询,删除,修改,数据,

asp.net, c#,gridview对数据进行绑定,增加,查询,删除,修改,数据, asp.net, c#,gridview对数据进行绑定,增加,查询,删除,修改,数据,

a304788727

ASP.NET三层架构添加删除修改查询实例

咳咳...本牛X程序使用小8+小5开发 q^0^p (vs2008+sql2005)!程序用三层结构实现了做网站最基本的添删改查功能,感觉比较适合入门者,因为考虑到新人学习之用 所以就不写存储过程和数据工厂了!只是普通的三层!希望能对三层苦手的朋友有帮助吧! 一般来说三层结构的中间层(BLL)应该只用来返回数据,收集错误和做判断,而不应该写入任何有关SQL的东东的!考虑到如果不那么写的话,中间层就没东西写了!所以就把SQL语句写到中间层了,大家明白就行了! 最后就是工厂三层 在实际大型项目团队开发的时候才会用得比较多,而单个人做中小项目的时候用工厂三层会很难做的,开发进度慢不说而且到后期客户要求修改的时候,会改到你想脱裤子去日经理的.......如果客户要求一定要用三层的话,这个时候MVC三层就是你的最佳解决方案了! 程序目录: /App_Code/ BLL 中间层 DAL 数据层 Model 数据实体 /App_Data/ 数据库 Default.aspx 主页 Edit.aspx 修改页 Login.aspx 登陆页 登陆:Admin 密码:Admin

ydjie

asp.net多选删除

.net多选删除 多选删除 .net多选删除 多选删除

cailufei

ASP.NET中为GridView添加删除提示框的方法

本文实例讲述了ASP.NET中为GridView添加删除提示框的方法。分享给大家供大家参考。具体分析如下: 在GridView中我们可以直接添加一个CommandField删除列来删除某行信息。但为了避免误操作引起的误删除,在删除操作者让操作者再确认下,完后再进行删除。 首先我们给我们的GridView 添加一个模板列,如下: 以下是引用片段: <ASP HeaderText=Delete ShowHeader=False> <ItemStyle ForeColor=Red> <ItemTemplate>  &lt;asp:LinkButton ID=

weixin_38558660
评论 8
收藏 已收藏
分享
返回顶部
zql2008
.NET社区 62,272 成员 668,968 内容