2011-12-10 75 views
0
<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 JavaScript代碼:如何使用JavaScript從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> 

誰能告訴我如何從GridView中獲取URL值?提前致謝。

+0

你的按鈕調用'playVideo()'。你發佈了'playAudio()'的JavaScript。哪個是對的? – gilly3

+0

你爲什麼要爲你的按鈕使用服務器控件?你想讓該按鈕導致回傳嗎? – gilly3

回答

1

試試這個,

<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> 
+0

Thankx for reply..i已經寫了給定的按鈕代碼,我得到的錯誤是服務器標籤不完整。 – Rembo

+0

@Rembo,我編輯了這個例子,這樣服務器標籤現在已經很好的形成了,你可以再試一次嗎? –

+0

你好朋友我使用的Windows媒體播放器播放視頻和以上我寫的函數名稱是playVideo()。我的代碼在這裏。 – Rembo

1

我會改變你的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; 
0
OnClientClick='<%# EVAL("VideoUrl", "return playAudio({0})") %>'/> 

使用這在你的按鈕。希望它有幫助。

相關問題