Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
1.60/5 (2 votes)
See more:
Hey all,
I just completed and learnt given task of embedding you tube video using c# in ASP.NET with the help of this great forum.
Now i am giving the same task more dynamically and here is the given scenario.
Embedded video links are saved in SQL table, let say table has total of 3 links, retrieve the links from table and embed all videos to a single page. in normal circumstances it will be very easy by fetching some data from table and show on page with the help of some kind of bounding control like repeater

write now i am able to just embed the single video by using panel
How can i achieve this task more dynamically
any kind of help will be deeply appreciated

Regards

What I have tried:

C#
string url = "https://www.youtube.com/embed/9bi9eDZUJPQ";
            var videoframe = new Literal();
            videoframe.Text = string.Format(@"<iframe width=""628"" height=""374"" src=""{0}"" frameborder=""0"" allowfullscreen></iframe>", url);
            Panel1.Controls.Add(videoframe);
Posted
Updated 3-Oct-19 1:55am
v2
Comments
ZurdoDev 3-Oct-19 7:05am    
Like you said, use a Repeater.

1 solution

Words like
Now i am giving the same task more dynamically and here is the given scenario.
are not a good choice though

anyways that's how you can use a repeater
Your aspx page

ASP.NET
<div>
<asp:Repeater ID="Repeat1" runat="server">
	<HeaderTemplate>
		<table class="tblcolor">
			<tr>
				
				<td>Name
				</td>
				<td>Video
				</td>
				
			</tr>
	</HeaderTemplate>
	<ItemTemplate>
		<tr>
			<td>
			<%#DataBinder.Eval(Container.DataItem,"Name")%>
			</td>
			<td>
			<%# "<iframe id='Video' width='450' height='350' src='" + DataBinder.Eval(Container.DataItem, "Url") + "' allowfullscreen></iframe>" %>
			</td>
		</tr>
	</ItemTemplate>
	<FooterTemplate>
		</table>
	</FooterTemplate>
</asp:Repeater>
</div>


Your code behind page

C#
public class NameVideo
{
	public string Name { get; set; }
	public string Url { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
	var data = new List<NameVideo>()
	{
		new NameVideo(){Name="Video1", Url ="https://www.youtube.com/embed/9bi9eDZUJPQ" },
		new NameVideo(){Name="Video2", Url=    "https://www.youtube.com/embed/Zx-JcXsbUqQ"}
	};

	Repeat1.DataSource = data;
	Repeat1.DataBind();
}
 
Share this answer
 
Comments
Aftab Iqbal Clips 7-Oct-19 7:03am    
when answering a question please
If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome
lets work to help developers not make them feel stupid
anyways
bundle of thanks for posting answer i learn new thing today because of you, have a nice day.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900