如何将Datalist中的控件绑定到新值?

时间:2013-10-30 09:37:35

标签: asp.net html5 video

  

我用 HTML5 视频控件制作了我的代码播放视频,我做了我的鳕鱼   播放视频但它没有用,因为我在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;



        }
    }
}

1 个答案:

答案 0 :(得分: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;
    }
}