'FmtClr'没有重载匹配委托'System.EventHandler'

时间:2013-04-24 10:59:09

标签: .net

以下代码抛出错误为 'FmtClr'没有重载匹配委托'System.EventHandler'

即使传递了处理程序参数

是我添加了scipt的位置的问题。

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup=    
CodeBehind="Default.aspx.cs" Inherits="TestCertification._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script runat="server">     
   public void FmtClr(object sender, ListViewItemEventArgs e)
   {
       Label LineTotal = (Label)
       e.Item.FindControl("LineTotalLabel");
       if (LineTotal.Text.Length > 7)
       { LineTotal.ForeColor = System.Drawing.Color.Red; }
       else
       { LineTotal.ForeColor = System.Drawing.Color.Black; }
   }
   </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">   
<asp:SqlDataSource ID="SqlDataSource1" runat="server" OnDataBinding="FmtClr"
ConnectionString="<%$ ConnectionStrings:FXVanilla50ConnectionString %>" 
SelectCommand="SELECT top 2 [AddressId], [City], [State], [PostalCode], [Country] FROM       [Addresses]">    
</asp:SqlDataSource>

<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">
   <ItemTemplate>
   <td>
   <asp:Label ID="LineTotalLabel" runat="server" Text='<%# Eval("City") %>' />
</td>
</ItemTemplate>
</asp:ListView> 
</asp:Content>

1 个答案:

答案 0 :(得分:0)

根据MSDN,SqlDataSource的DataBinding事件处理程序签名是objectEventArgs,但您指定了ListViewItemEventArgs。将您的签名更改为:

   public void FmtClr(object sender, EventArgs e)
   {
      //....
   }