C# 如何使用javascript从GridView获取URL?
播放URL的JavaScript代码:C# 如何使用javascript从GridView获取URL?,c#,javascript,asp.net,C#,Javascript,Asp.net,播放URL的JavaScript代码: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSourceVideo" > <Columns> <asp:BoundField DataField="VideoUrl" HeaderText="VideoUrl"
<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>
功能播放音频(URL){
如果(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();
}
}
有人能告诉我如何从gridview获取URL值吗?提前谢谢。试试这个
<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>
我会将您的BoundField更改为TemplateField
<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>
OnClientClick=''/>
在按钮中使用此选项。希望有帮助。您的按钮调用
playVideo()
。您发布了playAudio()
的JavaScript。哪一个是正确的?为什么要使用服务器控件作为按钮?你想让该按钮引起回发吗?谢谢你的回复。.我已经编写了给定的按钮代码,我得到的错误是服务器标记的格式不正确。@Rembo,我编辑了示例,因此服务器标记的格式现在很好,你能再试一次吗?朋友们好,我正在使用windows media player播放视频,上面我编写的函数名是playVideo()。我的密码在这里。
<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})") %>'/>