你怎么传递的Container.DataItem作为参数? [英] How do you pass a Container.DataItem as a parameter?
本文介绍了你怎么传递的Container.DataItem作为参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用一个中继器控制,我想传递一个参数为这样的:
I'm using a repeater control and I'm trying to pass a parameter as such:
<%# SomeFunction( DataBinder.Eval(Container.DataItem, "Id") ) %>
这基本上美其名曰:
It's basically calling:
public string SomeFunction(long id) {
return "Hello";
}
我不能够做到这一点,因为我得到一个错误:
I'm not able to achieve this as I get an error:
错误CS1502:最好的重载的方法匹配... SomeFunction(长ID)......有一些无效参数
error CS1502: The best overloaded method match ... SomeFunction(long id) ... has some invalid arguments.
任何想法?
推荐答案
您需要将结果转换为长,所以:
You need to cast the result to a long, so:
<%# SomeFunction( (long)DataBinder.Eval(Container.DataItem, "Id") ) %>
另一种方法是做这样的事情:
The alternative is to do something like this:
<%# SomeFunction(Container.DataItem) %>
和...
public string SomeFunction(object dataItem) {
var typedDataItem = (TYPED_DATA_ITEM_TYPE)dataItem;
// DO STUFF HERE WITH THE TYPED DATA ITEM
return "Hello";
}
这至少可以让你从数据项(数据行等)。
This at least allows you to work with multiple values from the data item (DataRows etc).
这篇关于你怎么传递的Container.DataItem作为参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文