开发者

Passing 2 values from Itemtemplates to code-behind

whats wrong with this code and i am getting this error:

Compiler Error Message: CS1502: The best overloaded method match for 'RenderName(str开发者_运维问答ing, string)' has some invalid arguments

<ItemTemplate>

<asp:Label ID="lblName" Text='<%# RenderName(Eval("Name"), Eval("Value")) %>'  runat="server" />

</ItemTemplate>

public string RenderName(string name, string value)
{
  //do stuffs..
}


If the return type of Eval() is an object (and I suspect it is), that would explain the error you're seeing. Maybe change your function to:

RenderName(object nameString, object valueString)

Then within the function, check the passed params for null, and either re-cast them to strings, or simply call ToString() on them.

Note: I'm not at a place where I can verify this in my own development environment, so apologies if this approach has a few hiccups.


the reason i was getting error is because i was not converting type

<ItemTemplate>
<asp:Label ID="lblName" Text='<%# RenderName(Eval("Name").ToString(), Eval("Value").ToString()) %>'  runat="server" />
</ItemTemplate>

its working as expected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜