GridView 的 HyperLinkField 僅支援導航網頁或下載檔案,無法直接喚起播放器播放影片。改用 ActiveX/Object 標籤嵌入 Windows Media Player。
<OBJECT id="RAOCX" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"
width="100%" height="385" VIEWASTEXT>
<PARAM NAME="AUTOSTART" VALUE="true" />
<PARAM NAME="SRC" VALUE="<%= VideoUrl %>" />
<PARAM NAME="CONTROLS" VALUE="imagewindow" />
<PARAM NAME="CONSOLE" VALUE="Clip1" />
<PARAM NAME="BACKGROUNDCOLOR" VALUE="#000000" />
<!-- 其他參數略 -->
</OBJECT>
關鍵:SRC 參數繫結後台屬性 VideoUrl (對應 <%=VideoUrl%>)。
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
string fileName = GridView1.Rows[index].Cells[6].Text; // 含副檔名
VideoUrl = "info\\" + fileName; // 伺服器相對路徑
}
影片檔案置於網站 info 目錄下,資料庫儲存檔名 (含副檔名)。GridView 以按鈕觸發 RowCommand 取得檔名並更新播放器來源。
<video> 標籤以獲跨平台相容性。/。