关于GridView1_SelectedIndexChanged的问题

zenggao 2008-04-05 11:01:39

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
this.prodid.Value = this.GridView1.SelectedValue.ToString();
this.qnt.Value = ((TextBox)this.GridView1.SelectedRow.Cells[6].FindControl("TextBox1")).Text.ToString();

this.SqlDataSource1.Insert();

}

其中this.SqlDataSource1.Insert();执行的是一个存储过程

我遇到的问题是每按一次选择按钮调用以上方法时会执行两次存储过程,为什么?怎样解决?

存储过程如下:
CREATE PROCEDURE Buyprod
@IDcard varchar(50),
@prodid varchar(50),
@qnt int
as
if exists(select * from cartbox where prodID=@prodid and IDcard=@IDcard and status=0)
begin
update cartbox set qnt=qnt+@qnt where prodID=@prodid and IDcard=@IDcard and status=0
end
else
begin
insert into cartbox(IDcard,prodid,qnt) values(@IDcard,@prodid,@qnt)
end
GO
...全文
1683 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhierhi 2011-05-05
  • 打赏
  • 举报
回复
遇到下面的错误:GridView1_SelectedIndexChanged”不是“ASP.usermanage_rolemanage_aspx”的成员
怎么办?
一品梅 2008-04-05
  • 打赏
  • 举报
回复
请参考5,7,8楼.
zenggao 2008-04-05
  • 打赏
  • 举报
回复
SelectionChangeCommitted 在哪?我找不到,我用的是GridView1控件
一品梅 2008-04-05
  • 打赏
  • 举报
回复
看看你的声明语句里有没有GridView1_SelectedIndexChanged
一品梅 2008-04-05
  • 打赏
  • 举报
回复
哦,明白了,你的声明语句和后台代码中都定义了该事件,将声明语句中的删除.
一品梅 2008-04-05
  • 打赏
  • 举报
回复
SelectionChangeCommited event is fired only when user changes the selected item (through UI), while SelectedIndexChanged and SelectedValueChanged can also be fired when currently displayed item is changed from code.

Comes in handy when you need to track user changes only and ignore changes you're doing through code.

hery2002 2008-04-05
  • 打赏
  • 举报
回复
检查你的代码,跟踪一下,估计是你在其他地方调用了.
http://forums.asp.net/p/1119144/1745402.aspx.
mohugomohu 2008-04-05
  • 打赏
  • 举报
回复
SelectedIndexChanged在加载数据的时候也会触发.
用SelectionChangeCommitted事件试试
zenggao 2008-04-05
  • 打赏
  • 举报
回复
没有高手吗?有没有人遇过这个问题?
viki117 2008-04-05
  • 打赏
  • 举报
回复
数据刷新引起的2次吧。。。就凭怎么点代码不好判断到底是怎么回事啊
andywiliang 2008-04-05
  • 打赏
  • 举报
回复
帮你顶高手来



请高手坐阵本群管理员
C C++ C# JAVA编程交流群:11713348

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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