在网格视图中显示YouTube视频
本文关键字:YouTube 视频 显示 网格 视图 | 更新日期: 2023-09-27 17:54:03
我已经在网格视图中显示了图像。但我不明白如何在网格视图中显示YouTube视频?
- 添加一个包含文字控件的模板列
- on itemdatabound用YouTube视频 的嵌入代码填充文字
的例子:
((Literal)e.Item.FindControl("litvideo")).Text = "<iframe width='"560'" height='"315'" src='"http://www.youtube.com/embed/r6BHyv6nkAs'" frameborder='"0'" allowfullscreen></iframe>";
<asp:TemplateField ControlStyle-CssClass="Row" HeaderText="YouTube Video">
<ItemTemplate>
<asp:Label ID="lblYTVideoURL" runat="server" Text=<%# Eval("YTVideoUrl") %>></asp:Label>
</ItemTemplate>
<ControlStyle CssClass="Row"></ControlStyle>
</asp:TemplateField>
然后从后面的代码:
protected void grvYoutubeVideo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl = (Label)e.Row.Cells[0].Controls[1];
if (lbl.Text != "")
{
//string YTVideoURL = lbl.Text; //"http://www.youtube.com/v/AyPzM5WK8ys";
//string OBJYTVideo = "<object width='"150'" height='"150'">";
//OBJYTVideo += "<param name='"movie'" value='"" + YTVideoURL + "'"></param>";
//OBJYTVideo += "<param name='"allowscriptaccess'" value='"always'"></param>";
//OBJYTVideo += "<embed src='"" + YTVideoURL + "'" type='"application/x-shockwave-flash'"";
//OBJYTVideo += "allowscriptaccess='"always'" width='"100%'" height='"100%'"></embed></object>";
//lbl.Text = OBJYTVideo;
}
}
}
试试这样做,你可以把所有这些放在。html中并打开。之后你可以很容易地把它添加到asp.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<object width="425" height="355">
<param name="movie" value="http://www.youtube.com/v/sSe_RmPlOLM" />
<param name="wmode" value="transparent" />
<embed src="http://www.youtube.com/v/sSe_RmPlOLM" type="application/x- shockwave-flash"
wmode="transparent" width="425" height="355" />
</object>
</div>
</form>
</body>
</html>
<asp:TemplateField HeaderText="Video">
<ItemTemplate>
<iframe id="video" width="420" height="250" frameborder="0" allowfullscreen src='<%# "http://www.youtube.com/embed/" + Eval("VideoURL").ToString().Split(new string[] { "v=" }, StringSplitOptions.None)[1] %>' frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>