“DataGrid_UpdateCommand”的重载均与委托“System.Web.UI.WebControls.GridViewUpdatedEventHandler”不匹配

itzhiren 2007-05-07 04:42:29
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。

编译器错误信息: CS0123: “DataGrid_UpdateCommand”的重载均与委托“System.Web.UI.WebControls.GridViewUpdatedEventHandler”不匹配

源错误:



行 12: <center>
行 13: <b>演示 EditCommandColumn</b>
行 14: <asp:GridView ID="score" runat="server" HeaderStyle-BackColor="#aaaadd" AlternatingRowStyle-BackColor="#eeeeee" AutoGenerateColumns="false" OnRowCommand="DataGrid_EditCommand" OnRowUpdated="DataGrid_UpdateCommand" OnRowCancelingEdit="DataGrid_CancelCommand">
行 15: <Columns>
行 16: <asp:CommandField HeaderText="操作区" EditText="编辑" UpdateText="更新" CancelText="取消" ButtonType="button" />


源文件: e:\ASP.NET\Samples\DataGridEditCommandColumn.aspx 行: 14

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

下面是相关代码:

//处理Update命令
public void DataGrid_UpdateCommand(object sender, GridViewCommandEventArgs e) {
//更新数据库中的信息
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = score.Rows[index];
string strName = row.Cells[1].Text;
int intChinese = Int32.Parse(((TextBox)row.Cells[2].Controls[0]).Text);
int intMath = Int32.Parse(((TextBox)row.Cells[3].Controls[0]).Text);
int intEnglish = Int32.Parse(((TextBox)row.Cells[4].Controls[0]).Text);

//string strName = e.Item.Cells[1].Text;
//int intChinese = Int32.Parse(((TextBox)e.Item.Cells[2].Controls[0]).Text);
//int intMath = Int32.Parse(((TextBox)e.Item.Cells[3].Controls[0]).Text);
//int intEnglish = Int32.Parse(((TextBox)e.Item.Cells[4].Controls[0]).Text);

//更新数据库中的数据
string strUpdate="update score set Chinese="+ intChinese +",Math="+ intMath +",English="+ intEnglish +" where Name='"+ strName +"'";
OleDbCommand MyComm = new OleDbCommand(strUpdate, MyConn);
MyComm.ExecuteNonQuery();

score.EditIndex = -1;
BindGridView();
=============================================================================================
页面上的代码是:

<asp:GridView ID="score" runat="server" HeaderStyle-BackColor="#aaaadd" AlternatingRowStyle-BackColor="#eeeeee" AutoGenerateColumns="false" OnRowCommand="DataGrid_EditCommand" OnRowUpdated="DataGrid_UpdateCommand" OnRowCancelingEdit="DataGrid_CancelCommand">
<Columns>
<asp:CommandField HeaderText="操作区" EditText="编辑" UpdateText="更新" CancelText="取消" ButtonType="button" />
<asp:BoundField HeaderText="姓名" DataField="Name" />
<asp:BoundField HeaderText="语文" DataField="Chinese" />
<asp:BoundField HeaderText="数学" DataField="Math" />
<asp:BoundField HeaderText="英语" DataField="English" />
</Columns>
</asp:GridView>
...全文
425 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hertz1220 2007-05-08
  • 打赏
  • 举报
回复
int index = Convert.ToInt32(e.CommandArgument);搂主那么写就是想获取当前选取的行,没必要那么写,那些写就可以了 int index = e.RowIndex
weizhuangzhi 2007-05-08
  • 打赏
  • 举报
回复
e.CommandArgument这个不对
你的写法就不对
参看:http://www.why100000.com/_articles/show_a_article.asp?autoid=120&tab=tabAspNet
itzhiren 2007-05-07
  • 打赏
  • 举报
回复
改了,但是又出现以下错误:
“System.Web.UI.WebControls.GridViewUpdatedEventArgs”并不包含“CommandArgument”的定义

weizhuangzhi 2007-05-07
  • 打赏
  • 举报
回复
事件参数值有误,应为GridViewUpdatedEventArgs :
DataGrid_UpdateCommand(Object sender, GridViewUpdatedEventArgs e)

62,025

社区成员

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

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

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

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