GridView RowDeleting 为什么执行了两次

null_name 2007-05-20 09:24:59
我在GridView里按选择后,再按删除
结果删除了两行记录,单步发现RowDeleting事件居然执行了两次,但有时候却执行一次,实在找不出原因,请有经验的哥们帮个忙解决一下啊
...全文
783 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenou851123 2007-05-21
  • 打赏
  • 举报
回复
还有的时候 点击"运行"的时候 出现 "什么什么错误.Dll的" 在点击一次就 可以运行了

但是有些时候在点击就总是提示这个错误 一定要在重新 大开网站 才行

还有在上级 Iframe的时候 我加了一个菜单 运行的时候加的菜单 出不开 一定要把
iframe 左边的菜单想 改一个名字 才出来

是我的VS2005有问题 还是Bug啊??
chenou851123 2007-05-20
  • 打赏
  • 举报
回复
我以前的 购物车的时候 有时候也是这样的

点一下 有时候买了一个 有时候买了两个

我是放在GridView1_SelectedIndexChanged事件里面的

看到你也有这个问题所以也提出来

程序真的没有问题!



void Session_Start(object sender, EventArgs e)
{
// 在新会话启动时运行的代码
Session["MyShoppingCart"] = new WebShoppingCart();
//读取当前统计人数
Application.Lock();
Application["Count"] = Convert.ToInt32(Application["Count"]) + 1;
Application.UnLock();
//写入Count.txt文件中
StreamWriter sw = new StreamWriter(Server.MapPath("Count.txt"), false);
sw.WriteLine(Application["Count"]);
sw.Close();
}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//创建实例
WebShoppingCart cart = (WebShoppingCart)Session["MyShoppingCart"];
try
{
string pid = GridView1.SelectedDataKey.Value.ToString();
if (cart != null)
{
cart.DeleteItem(pid);
Profile.ShoppingCart.DeleteItem(pid);
Total.Text = String.Format("合计:{0:c}", cart.TotalCost);
//删除后的绑定,下面可以不要因为Page_Load事件绑定了
//ShoppingCart cart = (ShoppingCart)Session["MyShoppingCart"];
//GridView1.DataSource = cart.Orders;
GridView1.DataBind();
}
}
catch
{
//这个是为了判断用户删除了商品
//但是点击后退按钮后商品还在
//在点击删除出现得异常,用刷新该页来解决
Response.Redirect("View_ShoppingCart.aspx");
}
}



namespace WendwCart //命名空间名称
{
[Serializable]
public class Stat_Class
{
private String ShangPinID; //商品ID
private String Sp_Name; //商品名称
private decimal Sp_Price; //商品价格
private int Sp_Quan; //商品数量

public string ItemID
{
get { return ShangPinID; }
//set { ShangPinID = value; }
}

public string ShangpinName
{
get { return Sp_Name; }
//set { Sp_Name = value; }
}

public decimal Price
{
get { return Sp_Price; }
//set { Sp_Price = value; }
}

public int Quantity
{
get { return Sp_Quan; }
set { Sp_Quan = value; }
}

//构造方法,初始化商品的各个属性
public Stat_Class(string ItemID, string ShangpinName, decimal Price, int Quantity)
{
ShangPinID = ItemID;
Sp_Name = ShangpinName;
Sp_Price = Price;
Sp_Quan = Quantity;
}
}

[Serializable]
public class WebShoppingCart
{
public WebShoppingCart()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
Hashtable Cart_Orders = new Hashtable();
//该属性返回Hashtable的ICollection集合作数据源
public ICollection Orders
{
get { return Cart_Orders.Values; }
}

//计算总价格属性
public decimal TotalCost
{
get {
decimal Total = 0;
foreach (DictionaryEntry entry in Cart_Orders)
{
Stat_Class order = (Stat_Class)entry.Value;
Total += (order.Price * order.Quantity);
}
return Total;
}
}

//添加物件方法
public void AddItem(Stat_Class Order)
{
Stat_Class order = (Stat_Class)Cart_Orders[Order.ItemID];
if (order != null)
{
order.Quantity += 1;
}
else
{
Cart_Orders.Add(Order.ItemID, Order);
}
}

//删除物件方法
public void DeleteItem(string ItemID)
{
if (Cart_Orders[ItemID] != null)
{
Cart_Orders.Remove(ItemID);
}
}
}
null_name 2007-05-20
  • 打赏
  • 举报
回复
绝对没有
weizhuangzhi 2007-05-20
  • 打赏
  • 举报
回复
是不是其他什么地方又调用了一次

62,243

社区成员

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

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

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

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