0

我用HTML5视频控件完成了我的代码播放视频,我很好地完成了我的 cod 来播放视频,但它不起作用,因为我将视频保存在 db 中,路径为“ ~/res/Files/test.ogv ”,问题是“ ~ / ”所以我做了我的代码来删除“ ~/ ”来播放视频。问题是当我替换“ ~/ ”时,我希望 HTML 控件挂起新值。

 protected void DL_Media_ItemDataBound(object sender, DataListItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        HtmlGenericControl video = e.Item.FindControl("vd") as HtmlGenericControl;
        HtmlGenericControl source = e.Item.FindControl("source") as HtmlGenericControl;
        string src = source.Attributes["src"].ToString();
        if (src != null)
        {
            string x = "~/";
            string y = " ";

              string result = src.Replace(x, y);
              src = result;



        }
    }
}
4

1 回答 1

0

这样做:

protected void DL_Media_ItemDataBound(object sender, DataListItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        HtmlGenericControl video = e.Item.FindControl("vd") as HtmlGenericControl;
        HtmlGenericControl source = e.Item.FindControl("source") as HtmlGenericControl;
        string src = source.Attributes["src"].ToString();
        if (!String.IsNullOrEmpty(src))
        {           
            src = src.Replace("~/","");
        }
        source.Attributes["src"] = src;
    }
}
于 2013-10-30T09:52:43.183 回答