如何将Datalist中的控件绑定到新值?(How to bind the control in Datalist with new value?)

系统教程 行业动态 更新时间:2024-06-14 17:01:31
如何将Datalist中的控件绑定到新值?(How to bind the control in Datalist with new value?)

我做了我的代码播放视频与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 (src != null) { string x = "~/"; string y = " "; string result = src.Replace(x, y); src = result; } } }

最满意答案

这样做:

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; } }

更多推荐

本文发布于:2023-04-20 16:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/d833c830f34514cb84b85232221d3d51.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   控件   如何将   到新   control

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!