如何在运行时从下拉列表中选择要播放的视频?

时间:2014-06-10 17:36:44

标签: c# asp.net

我的aspx页面代码。

<object id="obj" classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" 
                     codebase="http://www.microsoft.com/Windows/MediaPlayer/"> <param
 name="Filename" **value="video/yaarian.wmv"**> <param name="AutoStart"
 value="true"> <param name="ShowControls" value="true"> <param
 name="BufferingTime" value="2"> <param name="ShowStatusBar"
 value="true"> <param name="AutoSize" value="true"> <param
 name="InvokeURLs" value="false"> <embed id="emb"
 **src="video/yaarian.wmv"** type="application/x-mplayer2" autostart="1" enabled="1"  showstatusbar="1" showdisplay="1"
 showcontrols="1"
 pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" 
 CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,0,0"
 width="480" height="360"></embed> </object>

在代码中我输入了静态路径但我的要求是我想从数据库中选择一个视频名称,然后该视频将播放。我怎么能这样做?

我的.cs文件代码是

String s = videolist.SelectedItem.Value; String s1 = "", s2 = "";
//select path of video
db.con.Open();
try
{
    string str = "select * from video";
    db.com = new SqlCommand(str, db.con);
    SqlDataReader dr = db.com.ExecuteReader();

    while (dr.Read())
    {
        if (s.Equals(dr["Name"].ToString()))
        {
            s1 = dr["path"].ToString();

        }
    }

我想传递“s1”代替embed标签的src属性和param标签的value属性。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

标记&#34;对象&#34;和&#34;嵌入&#34;标签使用runat =&#34; server&#34;,这样你就可以访问这些项目的属性集合:

obj.Attributes["value"] = s1;
emb.Attributes["src"] = s1;