繁体   English   中英

'FmtClr'没有重载匹配代表'System.EventHandler'

[英]No overload for 'FmtClr' matches delegate 'System.EventHandler'

下面的代码抛出错误,因为“ 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>

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM