如何将Datalist中的控件绑定到新值?(How to bind the control in Datalist with new value?)
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; } } }我做了我的代码播放视频与HTML5视频控制,我做了我的鳕鱼播放视频,但它没有工作,因为我保存视频在数据库中的路径“ 〜/ 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; } } }I did my code play video with HTML5 video control , I did my cod well to play video but it didn't work because i saved the video in db with path " ~/res/Files/test.ogv " the problem was "~/" so i did my code to remove " ~/" to play the video . the problem is when I replace the " ~/" i want the HTML control pend the new value .
最满意答案
这样做:
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; } }Do like this:
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; } }更多推荐
发布评论