使用数据库链接显示YouTube视频

时间:2016-06-29 14:57:53

标签: c# asp.net

我需要一个代码,使用数据库中的链接

在asp.net网站上显示youtube视频

现在我使用下面的代码,但它不起作用: -

    <div class="panel-body">
        <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">


            <EmptyDataTemplate>
                <span>No data was returned.</span>
            </EmptyDataTemplate>

            <ItemTemplate>
                <div align="center">
                    <asp:Label ID="content_headLabel" runat="server" Text='<%# Eval("content_head") %>' Font-Size="Large" Font-Bold="True"/>
                </div>
                <br/>
                <div class="fa-file-video-o" align="center">
                <iframe src='<%#Eval("content_link") %>' runat="server" width="800" height="450"></iframe>
                <br/>
            </ItemTemplate>


        </asp:ListView>
    </div>
</div>


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CampusConnectionString %>" SelectCommand="SELECT [content_head], [content_link] FROM [inspire] WHERE ([type] = @type)">
    <SelectParameters>
        <asp:Parameter DefaultValue="Video" Name="type" Type="String"/>
    </SelectParameters>
</asp:SqlDataSource>

1 个答案:

答案 0 :(得分:1)

根据YouTube网址,您可以发出类似于以下HTML代码的内容,将视频嵌入到您的网页中:

<iframe width="560" height="315" src="https://www.youtube.com/embed/[your video ID goes here]" frameborder="0" allowfullscreen></iframe>

因此,如果您的YouTube视频网址为https://www.youtube.com/watch?v=myVideoID,则将“watch?v =”替换为“embed /”,然后将该字符串用作src属性的值在上面的iframe标记中。