Singh vivek Pratap
Singh vivek Pratap

Reputation: 29

Display youtube video using link from database

i need a code to display youtube video in asp.net website using link present in database

now i am using below code but its not working:-

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

Upvotes: 0

Views: 2056

Answers (1)

wablab
wablab

Reputation: 1743

Given a youtube URL, you can emit something similar to the following HTML code to embed the video in your page:

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

So, if your youtube video URL was https://www.youtube.com/watch?v=myVideoID, you'd replace the "watch?v=" with "embed/", and then use that string as the value of the src attribute in that iframe tag above.

Upvotes: 1

Related Questions