Search code examples
c#asp.netinline-code

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


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?

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

Solution

  • 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.