listviewvideo.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Text;
using System.IO;
using System.Configuration;
public partial class listviewvideo : System.Web.UI.Page
{
//Connection with DataBase
SqlConnection connect = new SqlConnection("Data Source=(local);Initial Catalog=Image;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid(); //PostBack Function BindGrid()
}
connect.Open();
SqlDataAdapter adapter = new SqlDataAdapter("select * from tblFiles", connect);
DataSet ds = new DataSet();
adapter.Fill(ds); //SqlDataAdapter ID
listview.DataSource = ds; //Listview ID
listview.DataBind();
}
//Upload a Video from Local system
protected void btnupload_Click(object sender, EventArgs e)
{
FileUpload FileUpload1 = (FileUpload)listview.FindControl("FileUpload1");
using (BinaryReader br = new BinaryReader(FileUpload1.PostedFile.InputStream))
{
byte[] bytes = br.ReadBytes((int)FileUpload1.PostedFile.InputStream.Length); //Store the Video in to byte format
string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
//Inserting the value to DataBase
cmd.CommandText = "insert into tblFiles(Name, ContentType, Data) values (@Name, @ContentType, @Data)";
cmd.Parameters.AddWithValue("@Name", Path.GetFileName(FileUpload1.PostedFile.FileName)); //Name of the Video
cmd.Parameters.AddWithValue("@ContentType", "video/mp4"); //Video format
cmd.Parameters.AddWithValue("@Data", bytes); //Video stored in byte format
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
Response.Redirect(Request.Url.AbsoluteUri);
}
private void BindGrid()
{
string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; //"constr" ConnectionString name used in Web.config
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select Id, Name from tblFiles";
cmd.Connection = con;
con.Open();
//Solution:1
//ListViewDataItem item = (ListViewDataItem)(sender as Control).NamingContainer;
//DataList DataList1 = (DataList)item.FindControl("DataList1");
//Solution:2
//DataList DataList1 = (DataList)listview.FindControl("DataList1");
DataList1.DataSource = cmd.ExecuteReader(); //Datalist ID
DataList1.DataBind();
con.Close();
}
}
}
protected void FlashVideo1_Load(object sender, EventArgs e)
{
}
}
listviewvideo.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="listviewvideo.aspx.cs" Inherits="listviewvideo" %>
<%@ Register assembly="ASPNetFlashVideo.NET3" namespace="ASPNetFlashVideo" tagprefix="ASPNetFlashVideo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>
Youtube Videos
</title>
<style>
.myButton
{
-moz-box-shadow:inset 0px 1px 0px 0px #f5978e;
-webkit-box-shadow:inset 0px 1px 0px 0px #f5978e;
box-shadow:inset 0px 1px 0px 0px #f5978e;
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #f24537), color-stop(1, #c62d1f));
background:-moz-linear-gradient(top, #f24537 5%, #c62d1f 100%);
background:-webkit-linear-gradient(top, #f24537 5%, #c62d1f 100%);
background:-o-linear-gradient(top, #f24537 5%, #c62d1f 100%);
background:-ms-linear-gradient(top, #f24537 5%, #c62d1f 100%);
background:linear-gradient(to bottom, #f24537 5%, #c62d1f 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f24537', endColorstr='#c62d1f',GradientType=0);
background-color:#f24537;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #d02718;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-family:arial;
font-size:15px;
font-weight:bold;
padding:10px 55px;
text-decoration:none;
text-shadow:0px 1px 0px #810e05;
}
.myButton:hover
{
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #c62d1f), color-stop(1, #f24537));
background:-moz-linear-gradient(top, #c62d1f 5%, #f24537 100%);
background:-webkit-linear-gradient(top, #c62d1f 5%, #f24537 100%);
background:-o-linear-gradient(top, #c62d1f 5%, #f24537 100%);
background:-ms-linear-gradient(top, #c62d1f 5%, #f24537 100%);
background:linear-gradient(to bottom, #c62d1f 5%, #f24537 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#c62d1f', endColorstr='#f24537',GradientType=0);
background-color:#c62d1f;
}
.myButton:active
{
position:relative;
top:1px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<img src="youtube.PNG" />
<div class="thumbnail" style="width:13%;height:661px; background-color:white;float:left;">
<asp:ListView ID="listview" runat="server">
<ItemTemplate>
<div>
<table width="100%">
<tr>
<td> <%--ListView IMAGE--%>
<asp:HyperLink ID="hyperlink" runat="server" ImageUrl="~/image.PNG" Text="Watch Video" NavigateUrl="~/Wildlife.mp4" ImageHeight="100" onclick="Wildlife.mp4"></asp:HyperLink>
</td>
</tr>
<tr>
<td> <%--ListView IMAGE--%>
<asp:HyperLink ID="hyperlink1" runat="server" ImageUrl="~/image2.PNG" Text="Watch Video" NavigateUrl="~/Wildlife.mp4" ImageHeight="100"></asp:HyperLink>
</td>
</tr>
<tr>
<td> <%--ListView IMAGE--%>
<asp:HyperLink ID="hyperlink2" runat="server" ImageUrl="~/image3.PNG" Text="Watch Video" NavigateUrl="~/Wildlife.mp4" ImageHeight="100"></asp:HyperLink>
</td>
</tr>
<tr>
<td> <%--ListView IMAGE--%>
<asp:HyperLink ID="hyperlink3" runat="server" ImageUrl="~/image4.PNG" Text="Watch Video" NavigateUrl="~/Wildlife.mp4" ImageHeight="100"></asp:HyperLink>
</td>
</tr>
<tr>
<td> <%--ListView IMAGE--%>
<asp:HyperLink ID="hyperlink4" runat="server" ImageUrl="~/image5.PNG" Text="Watch Video" NavigateUrl="~/Wildlife.mp4" ImageHeight="100"></asp:HyperLink>
</td>
</tr>
<tr>
<td> <%--ListView IMAGE--%>
<asp:HyperLink ID="hyperlink5" runat="server" ImageUrl="~/image6.PNG" Text="Watch Video" NavigateUrl="~/Wildlife.mp4" ImageHeight="100"></asp:HyperLink>
</td>
</tr>
</table>
</div>
</div>
<div style="width:80%;height:680px;background-color:white;float:left;margin-left:30px;">
<div>
<table>
<tr runat="server">
<td runat="server">
<%--FlashVideo--%>
<ASPNetFlashVideo:FlashVideo ID="FlashVideo1" runat="server" Height="500" Width="1050"></ASPNetFlashVideo:FlashVideo>
<%--FileUpload--%>
<asp:FileUpload ID="FileUpload1" runat="server" CssClass="myButton" />
<asp:Button ID="btnupload" runat="server" Text="Upload" OnClick="btnupload_Click" CssClass="myButton" />
<asp:DataList ID="DataList1" Visible="true" runat="server" AutoGenerateColumns="false" RepeatColumns="2" CellSpacing="5">
<ItemTemplate>
<ul>
<li>
<%# Eval("Name") %>
</li>
</ul>
<a class="player" style="height:300px; width:300px; display:block" href='<%# Eval("Id","File.ashx?Id={0}") %>'></a>
</ItemTemplate>
</asp:DataList>
<script src="FlowPlayer/flowplayer-3.2.12.min.js" type="text/javascript"></script>
<script type="text/javascript">
flowplayer("a.player", "FlowPlayer/flowplayer-3.2.16.swf",
{
plugins:
{
pseudo:
{
url: "FlowPlayer/flowplayer.pseudostreaming-3.2.12.swf"
}
},
clip: { provider: 'pseudo', autoPlay: false },
}
);
</script>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:ListView>
</div>
</form>
</body>
</html>
嗨, - &GT;我将在ListView中显示图像,对于我分配了视频的每个图像 - &GT;点击图片即可播放视频 - &GT;之后我将使用FileUpload Tag从本地系统上传视频 - &GT;在此ID不显示在ListViewVideo.aspx.cs中,如果我删除Listview,则ID正在运行 - &GT;什么是解决方案,我上传了我的完整编码,帮助 给我解决方案
答案 0 :(得分:0)
我认为这是电话订单中的一个问题。
将部分从Page_Load移动到Page_PreRender可能会帮助您。 页面生命周期中的调用顺序如下:
您可以在以下链接中查找有关活动阶段的详细信息以及有关如何使用它们的建议: https://msdn.microsoft.com/en-us/library/ms178472.aspx#lifecycle_events