重载均与委托“System.EventHandler”不匹配?
我想点击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;
}
}
}
[解决办法]
LinkButton 不能使用 DataListCommandEventArgs e
[解决办法]
LinkButton 的应该是
void LinkButton_Click(Object sender, EventArgs e)
{
......
}