简体   繁体   English

长时间绑定到用户控件属性

[英]binding long to user control property

I seem to have run across an issue with binding and I have looked everywhere to try to resolve it. 我似乎遇到了绑定问题,并且四处寻找解决问题的方法。

I have a user control in ASP.NET that has a Channel ID public property which is a long. 我在ASP.NET中有一个用户控件,该控件具有一个很长的Channel ID公共属性。 I have added this user control to an empty ASPX page for testing. 我已将此用户控件添加到一个空的ASPX页中进行测试。 When I simply add a number for this property value (ie ChannelID="9" ) then it works perfectly. 当我简单地为此属性值添加一个数字(即ChannelID="9" )时,它就可以正常工作。 When I try to do the following: 当我尝试执行以下操作时:

ChannelID="<%#: ChannelID %>" 

where ChannelID is a variable on the hosting ASPX page, it tells me it cannot convert from string to long as a compilation error. ChannelID是托管ASPX页面上的变量,它告诉我只要编译错误它就不能从字符串转换为字符串。

What I have gathered so far through my research is that the data binding functions convert values to strings rather than retaining their original data types. 到目前为止,我通过研究收集到的是数据绑定函数将值转换为字符串,而不是保留其原始数据类型。

What I am trying to accomplish is to have multiple user controls in a single page that all bind a property through a shared interface to the same value of the host page. 我要完成的工作是在单个页面中具有多个用户控件,这些控件都通过共享接口将属性绑定到主机页面的相同值。 I know that I could do this in code behind but that is what I am trying to avoid. 我知道我可以在后面的代码中做到这一点,但这就是我要避免的事情。 I also know that I could simply change the data type to string and then convert it before it is sent from the user control to the database....that will be the route I go if I cannot find another solution. 我也知道我可以简单地将数据类型更改为字符串,然后在将其从用户控件发送到数据库之前将其转换....如果找不到其他解决方案,这就是我要走的路线。

There is not really code I can post because the scenario is extremely basic.But here is the declaration of the user code on the host page: 因为该场景非常基础,所以我实际上没有可以发布的代码。但这是宿主页面上用户代码的声明:

<UC:ChanControl ID="ChanControl1" runat="server" IsActiveView="true"
    DisplayMode="Normal" ChannelID="<%#: ChannelID%>" /> 

Again, the ChannelID property in the host page and the user control are both set to long. 同样,宿主页和用户控件中的ChannelID属性都设置为long。

Any suggestions would be greatly appreciated. 任何建议将不胜感激。 Thanks. 谢谢。

试试这个ChannelID='<%#: Eval(ChannelID) %>'

ChannelID='<%#: Eval(ChannelID).ToString() %>'

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

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