找到你要的答案

Q:Error in aspx page when using class inside of span tag

Q:错误在ASPX页面使用类的时候在span标签

Sorry about the ambiguous title but it is the best I could do.

I am getting the following error

Argument type 'object' is not assignable to parameter type 'int'

The line that is referenced is:

<span class = '<%#BindPageNumberClass(DataBinder.Eval(Container, "DataItem")) %>' onclick="dtpaging_Page_Selected('<%# DataBinder.Eval(Container, "DataItem")%>');">

This line produces the red squiggle that is indicative of an error in the first portion

<span class = '<%#BindPageNumberClass(DataBinder.Eval(Container, "DataItem")).....

So naturally I thought I should convert this line to Int32 but sadly enough it did not work and gave me almost the same error. I searched the internet and tried many failed attempts at fixing this error.

Has anyone else ran into this issue? What I find perplexing is that only the first part of the line is erroring out when the rest of the line (which appears to be the exact same code) is not erroring out?

对不起,模糊的标题,但它是最好的,我可以做。

我得到以下错误

参数类型的对象是不可转让的参数类型“int”

被引用的线是:

<span class = '<%#BindPageNumberClass(DataBinder.Eval(Container, "DataItem")) %>' onclick="dtpaging_Page_Selected('<%# DataBinder.Eval(Container, "DataItem")%>');">

这条线产生的红色花体,第一部分是指示一个错误

<span class = '<%#BindPageNumberClass(DataBinder.Eval(Container, "DataItem")).....

所以我想我应该把这线Int32但令人遗憾的是,它不工作了,我几乎相同的错误。我搜索互联网,并尝试了许多失败的尝试修复这个错误。

有没有其他人碰到这个问题?我发现令人费解的是,只有行的第一部分则在其余的线(这似乎是完全相同的代码)不则么?

answer1: 回答1:

The return value of DataBinder.Eval is an object. Assuming your BindPageNumberClass takes an int as it's parameter, you'll need to cast the return of the eval call to int using (int)DataBinder.Eval(Container, "DataItem"):

<span class='<%#BindPageNumberClass((int)DataBinder.Eval(Container, "DataItem")) %>'
    onclick="dtpaging_Page_Selected('<%# DataBinder.Eval(Container, "DataItem")%>');">

DataBinder的返回值是一个对象的评价。假设你的BindPageNumberClass接受一个int作为它的参数,你就需要转换的eval调用返回int(int)使用DataBinder. eval(容器,“DataItem”):

<span class='<%#BindPageNumberClass((int)DataBinder.Eval(Container, "DataItem")) %>'
    onclick="dtpaging_Page_Selected('<%# DataBinder.Eval(Container, "DataItem")%>');">
c#  asp.net  .net