[英]How to get URL from GridView using javascript?
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="SqlDataSourceVideo" >
<Columns>
<asp:BoundField DataField="VideoUrl" HeaderText="VideoUrl"
SortExpression="VideoUrl" />
<asp:BoundField DataField="ID" HeaderText="ID"
SortExpression="ID" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="Video_Name" HeaderText="Video_Name"
SortExpression="Video_Name" />
<asp:CommandField ShowDeleteButton="True" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="ButtonPlay" runat="server" CommandName="Play"
CommandArgument='<%# DataBinder.Eval(Container.DataItem,"VideoUrl") %>'
Text="Play" OnClientClick="playVideo()"></asp:Button>
播放網址的JavaScript代碼:
<script type="text/javascript" language="javascript">
function playAudio(URL){
if (URL != "")
{
document.Player.filename = URL;
document.getElementsByName("mediaPlayer").src=URL;
document.getElementsByName("mediaPlayer").play();
document.Player.showcontrols = true;
document.Player.height = 40;
document.Player.play();
}
}
</script>
誰能告訴我如何從gridview獲取URL值? 提前致謝。
嘗試這個,
<asp:Button ID="ButtonPlay" runat="server" CommandName="Play"
CommandArgument='<%# DataBinder.Eval(Container.DataItem,"VideoUrl") %>'
Text="Play"
OnClientClick='<%# DataBinder.Eval(Container.DataItem,"VideoUrl", "playVideo('{0}')") %>'>
</asp:Button>
我會將你的BoundField更改為TemplateField
<asp:TemplateField SortExpression="VideoUrl" HeaderText="Video Url">
<span class='videoUrl<%# DataBinder.Eval(Container, "RowIndex") %>'><%# Eval("VideoUrl") %></span>
</asp:TemplateField>
然后,從第三行獲取網址:
var span = document.getElementsByClassName("videoUrl3")[0];
var url = span.textContent ? span.textContent : span.innerHTML;
OnClientClick='<%# EVAL("VideoUrl", "return playAudio({0})") %>'/>
在你的按鈕中使用它。希望它有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.