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>

JavaScript code for play 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>

Can anyone tell me how to get URL value from gridview? Thanks in advance.

2
  • Your button calls playVideo(). You posted the JavaScript for playAudio(). Which is correct? Commented Dec 10, 2011 at 6:42
  • Why are you using a server control for your button? Do you want that button to cause a postback? Commented Dec 10, 2011 at 6:45

3 Answers 3

1

Try this,

<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>
Sign up to request clarification or add additional context in comments.

3 Comments

Thankx for reply..i has written given button code, i got error that is the server tag is not well formed.
@Rembo, I edited the example so the server tag is now well formed, can you try again?
Hello friends i am using windows media player to play videos and above i written function name is playVideo(). my code is here.
1

I would change your BoundField into a TemplateField

<asp:TemplateField SortExpression="VideoUrl" HeaderText="Video Url">
    <span class='videoUrl<%# DataBinder.Eval(Container, "RowIndex") %>'><%# Eval("VideoUrl") %></span>
</asp:TemplateField>

Then, to get the url from row three:

var span = document.getElementsByClassName("videoUrl3")[0];
var url = span.textContent ? span.textContent : span.innerHTML;

Comments

0
OnClientClick='<%# EVAL("VideoUrl", "return playAudio({0})") %>'/> 

use this in your button .Hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.