Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • v4nilla 7 posts 26 karma points
    May 05, 2010 @ 04:35
    v4nilla
    0

    Details View to Display swf file from Media Library

    Umbraco Version: 4.0.2

    ASP.NET Version: 2.0

    Windows 7 & IIS 7

    I have a customer usercontrol with an asp:detailsview that is populated when a parent item is selected from an asp:gridview. Inside the detailsview is an ItemTemplate where I am trying to display a flash swf file from the media library based on the id that is returned when the detailsview is bound. The problem I have it the flash <embed> and <object> tags are not databound, so I can't simply grab the bound value and update the tags.

    Here is a the code from the custom usercontrol:

    <asp:DetailsView ID="Detail" runat="server" DataSourceID="DetailData" AutoGenerateRows="false" BorderWidth="0" CellPadding="5" OnDataBound="Detail_Bound">
    <Fields>
    <asp:TemplateField HeaderText="Demonstration Movie">
    <ItemTemplate>

    <script type="text/javascript">
    AC_FL_RunContent('codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0', 'width', '640', 'height', '520', 'src', '/flash/movie-container', 'FlashVars', 'exercise=<%# theFile %>', 'quality', 'high', 'pluginspage', 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash', 'movie', '/flash/movie-container'); //end AC code
    </script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="640" height="520">
    <param name="movie" value="/flash/movie-container.swf" />
    <param name="quality" value="high" />
    <param name="FlashVars" value="exercise=<%# theFile %>" />
    <embed src="/flash/movie-container.swf" quality="high" FlashVars="exercise=<%# theFile %>" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="640" height="520"></embed>
    </object></noscript>
    </ItemTemplate>
    </asp:TemplateField>
    </Fields>
    </asp:DetailsView>

    in the codebehind:

    public string somestring(string stringID)
    {
    string theVideo;
    if (String.IsNullOrEmpty(stringID) == true)
    {
    theVideo = "/flash/no-img.swf";
    return theVideo;
    }
    else
    {
    int eID = Convert.ToInt32(stringID);
    theVideo = umbraco.library.GetMedia(eID, false).Current.SelectSingleNode("//data[@alias=\"umbracoFile\"]").Value;
    return theVideo;
    }
    }
    protected void Detail_Bound(object sender, EventArgs e)
    {
    string theFileID = this.Eval("Video").ToString();
    theFile = somestring(theFileID);
    }

    the error i receive when i select an item from the gridview:

    Databinding methods such as Eval(), XPath(), and Bind() can only be used in 
    the context of a databound control.
  • Chris Dunn 210 posts 401 karma points
    May 05, 2010 @ 05:17
    Chris Dunn
    0

    Try calling eval from within the template code and passing that value directly to the somestring function and returning that value for all "theFile" items.

    <%# somestring(Eval(Container.DataItem,"Video")) %>

    Or in the code behind for Detail_Bound use the DataBinder.Eval vs Eval.

    string theFileID = DataBinder.Eval(e.Item.DataItem,"Video")

    Also try casting the dataitem directly to a datarowview.

    DataRowView row = (DataRowView) e.Item.DataItem;
    string theFileID = row["Video"].ToString();

     

    -Chris

  • v4nilla 7 posts 26 karma points
    May 11, 2010 @ 04:18
    v4nilla
    0

    hmmm. Doesn't seem to be working. When I attempt e.Item.xxx i am told System.EventArgs does not contain a definition for Item. I played around with different Arguments, but it doesn't seem to matter, e never contains Item.

Please Sign in or register to post replies

Write your reply to:

Draft