0

我在一个 aspx 页面中有一个 eval,它在 gridview 的模板中有一个 eval。我的问题是 eval 调用了一个带有对象参数的方法。我可以更改方法以接受正确的参数并将 cast 与 eval 语句一起使用。

我需要这样的东西:

<%# MyClas.MyMethod((string)Eval("Param1"),(int)Eval("Param2"), (string)Eval("Param3"))%>

4

1 回答 1

1

You could create your signature to contain the right types or type object. This is entirely dependent on the data and your preference. If any of your parameters return NULL, there may be an exception with the casting of your evaluated data item. I personally prefer the first option, but then I always ensure that there will not be a null in the result set.

Option 1:

<%# MyClas.MyMethod((string)Eval("Param1"),(int)Eval("Param2"), (string)Eval("Param3"))%>

Code:

public string MyMethod(string param1, int param2, string param3) {
    return "";
}

or Option 2:

<%# MyClas.MyMethod(Eval("Param1"),Eval("Param2"), Eval("Param3"))%>

Code:

public string MyMethod(object param1, object param2, object param3) {
    return "";
}

I hope this helps.

于 2012-11-06T10:33:00.073 回答