简体   繁体   中英

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. I have added this user control to an empty ASPX page for testing. When I simply add a number for this property value (ie ChannelID="9" ) then it works perfectly. 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.

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.

Any suggestions would be greatly appreciated. Thanks.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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