开发者

multiple statments in inline c# on and asp.net page

开发者 https://www.devze.com 2023-03-21 18:24 出处:网络
I have the following line in my aspx file: <asp:Image ID=\"Image1\" runat=\"server\" ImageUrl=\'<%# MediaHelper.GetMediaUrl(Container.DataItem) %>\' Height=\"114\" Width=\"152\"/>

I have the following line in my aspx file:

<asp:Image ID="Image1" runat="server" ImageUrl='<%# MediaHelper.GetMediaUrl(Container.DataItem) %>' Height="114" Width="152"/>

Is it possible to add another line to the inline c# something like this?

&l开发者_运维百科t;asp:Image ID="Image1" runat="server" ImageUrl='<%# MediaHelper.GetMediaUrl(Container.DataItem); SetImageSize(this) %>' Height="114" Width="152"/>


I am afraid that this is not possible. But you could write another method on this helper class which will invoke the two operations at once.

<asp:Image 
    ID="Image1" 
    runat="server" 
    ImageUrl='<%# MediaHelper.GetMediaUrlAndSetImageSize(Container.DataItem, this) %>' 
    Height="114" 
    Width="152"
/>

Also mixing C# code with ASPX might lead to spaghetti. I would tend to avoid it as much as possible.


You could use multiple method calls to accomplish what you are trying to do:

<asp:Image 
    ID="Image1" 
    runat="server" 
    ImageUrl='<%# MediaHelper.GetMediaUrl(Container.DataItem) %>' 
    Height="<%# MediaHelper.GetMediaHeight(Container.DataItem) %>" 
    Width="<%# MediaHelper.GetMediaWidth(Container.DataItem) %>"
/>

Or just bind an object to the control that has all of those values exposed as properties.

0

精彩评论

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