重载均与委托“System.EventHandler”不匹配?

mjtfzh 2007-01-07 09:28:51
我想点击LinkButton1和LinkButton2后都执行DataList1_ItemCommand

错误提示:“DataList1_ItemCommand”的重载均与委托“System.EventHandler”不匹配
<asp:LinkButton ID="LinkButton4" CommandName="category" runat="server" text="类别信息" OnClick="DataList1_ItemCommand" /><br>//这一行是红色
行 30:
<asp:LinkButton ID="LinkButton5" CommandName="supplier" runat="server" text="供应商" OnClick="DataList1_ItemCommand"/>
行 31: </td>



.aspx部分代码

<asp:DataList ID="DataList1" runat="server" Width="275px" OnSelectedIndexChanged="DataList1_SelectedIndexChanged" DataKeyField="pro_id">
<ItemTemplate>
<table style="width: 174px">
<tr>
<td style="width: 70px"><asp:Image ID="Image3" runat="server" Width="100px" Height="100px" ImageUrl='<%# Eval("photo","pic_{0}.bmp") %>'></asp:Image>

</td>
<td style="width: 1987px">产品:<br>
单价:<br>
单位:<br>
<asp:LinkButton ID="LinkButton4" CommandName="category" runat="server" text="类别信息" OnClick="DataList1_ItemCommand" /><br>
<asp:LinkButton ID="LinkButton5" CommandName="supplier" runat="server" text="供应商" OnClick="DataList1_ItemCommand"/>
</td>
<td>
<asp:LinkButton ID="LinkButton6" CommandName="select" runat="server" text='<%# Eval("pro_name") %>'/><br>
<%# Eval("price") %><br>
<%# Eval("unit") %>
</td>
</tr>

</table>
</ItemTemplate>
</asp:DataList>
.cs部分代码
protected void DataList1_ItemCommand(object sender, DataListCommandEventArgs e)
{
string commstr1 = "select a.pro_id,b.provider_string,c.class_string from 产品表 as a,供应资料 as b,产品类别 as c where pro_id='" +
DataList1.DataKeys[e.Item.ItemIndex] + "' and b.provider=a.provider and a.pro_class=c.class_string";
SqlConnection conn1 = new SqlConnection(connstr);
SqlCommand comm1 = new SqlCommand(commstr1, conn1);
conn1.Open();
SqlDataReader dr2 = comm1.ExecuteReader();
if (dr2.Read() == true)
{
switch (e.CommandName)
{
case "catagory": Label6.Text = dr2["class_string"].ToString(); break;
case "supplier": Label7.Text = dr2["provider_string"].ToString(); break;
}
}


}

...全文
3845 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
facebookdotcom 2008-12-20
  • 打赏
  • 举报
回复
mjtfzh 2007-01-07
  • 打赏
  • 举报
回复
将protected void DataList1_ItemCommand(object sender, DataListCommandEventArgs e)
改为:protected void DataList1_ItemCommand(object sender, EventArgs e)


错误提示:“System.EventArgs”并不包含“Item”的定义

string commstr1 = "select a.pro_id,b.provider_string,c.class_string from 产品表 as a,供应资料 as b,产品类别 as c where pro_id='" +
行 73: DataList1.DataKeys[e.Item.ItemIndex] + "' and b.provider=a.provider and a.pro_class=c.class_string";//这一行是红色的
行 74: SqlConnection conn1 = new SqlConnection(connstr);
行 75: SqlCommand comm1 = new SqlCommand(commstr1, conn1);
怎么获取那一行的数据?
mjtfzh 2007-01-07
  • 打赏
  • 举报
回复
在设计模式下不能双击LinkButton4进入.cs下,新增LinkButton_Click(Object sender, EventArgs e) 怎么办呢?
mjtfzh 2007-01-07
  • 打赏
  • 举报
回复
将protected void DataList1_ItemCommand(object sender, DataListCommandEventArgs e)
改为:protected void DataList1_ItemCommand(object sender, EventArgs e)


错误提示:“System.EventArgs”并不包含“Item”的定义

怎么获取那一行的数据?
burn3tt 2007-01-07
  • 打赏
  • 举报
回复
LinkButton 的应该是
void LinkButton_Click(Object sender, EventArgs e)
{
......
}
孟子E章 2007-01-07
  • 打赏
  • 举报
回复
LinkButton 不能使用 DataListCommandEventArgs e

62,063

社区成员

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

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

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

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