HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText = "Video">
<ItemTemplate>
<iframe id="video" width="200" height="200" frameborder="0" allowfullscreen src='<%# "http://www.youtube.com/embed/" + Eval("VideoUrl").ToString().Split(new string[] { "v=" }, StringSplitOptions.None)[1] %>'>
</iframe>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Namespaces
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT VideoId, VideoUrl FROM YoutubeVideos", con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
sda.Fill(dt);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
}
}
}
SQL
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[YoutubeVideos](
[VideoId] [int] NOT NULL,
[VideoUrl] [nvarchar](1000) NOT NULL,
CONSTRAINT [PK_YoutubeVideos] PRIMARY KEY CLUSTERED
(
[VideoId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT INTO [YoutubeVideos]
SELECT 1, 'https://www.youtube.com/watch?v=cWuvnc6u93A'
UNION ALL
SELECT 2, 'https://www.youtube.com/watch?v=lnVSNz_Q1wM'
Screenshot