Showing posts with label video. Show all posts
Showing posts with label video. Show all posts

Friday, 15 November 2013

Play All type of Video files in GridView with Literal Control using C#

Follow the instructions:

1.)  First Select asp Literal Control from Toolbox.

<asp:GridView ID="GridView1" runat="server" GridLines="None" ShowHeader="False" Width="100%"
                        AutoGenerateColumns="False" AllowPaging="true" PageSize="3" OnPageIndexChanging="GridView1_PageIndexChanging">
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <table style="width: 100%" cellpadding="5px">
                                        <tr>
                                            <td valign="top">
                                                <h2 style="text-align: left; color: #771212">
                                                    <%#Eval("Title")%></h2>
                                                <hr />
                                                <div style="font-size: 13px; color: Gray; text-align: right">
                                                    Posted on <%#Eval("PostingDate")%></div>
                                                <p style="font-size: 15px; color: Black">
                                                    <div style="width: 280px; height: 220px; float: left; text-align:left">
                                                        <asp:Label ID="lblvideo" runat="server" Visible="false"><%#Eval("VedioFile")%>.<%#Eval("OriginalFileExtn") %></asp:Label>
                                                        
                                                        <asp:Literal ID="Literal1" runat="server"></asp:Literal>
                                                    </div>
                                                    <%#Eval("Description")%></p>
                                            </td>
                                        </tr>
                                    </table>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <PagerSettings Mode="NextPreviousFirstLast" FirstPageText="First" PreviousPageText="Previous"
                            NextPageText="Next" LastPageText="Last" />
                    </asp:GridView>

2.)  Copy and paste this code to your code file on GridView Binding


DataTable dt = App.GetDataTable("Select * from Blog order by PostingDate DESC");
            GridView1.DataSource = dt;
            GridView1.DataBind();
            foreach (GridViewRow gvrow in GridView1.Rows)
            {
                Label vurl = (Label)gvrow.FindControl("lblvideo");
                Literal Literal1 = (Literal)gvrow.FindControl("Literal1");
                string myobj = "";
                if (vurl.Text != "" && vurl.Text != null)
                {
                    myobj += "<video width='250' height='200' controls='controls' data-setup='{}'>";
                    myobj += "<source src='File/BlogFile/" + vurl.Text + "' type='video/ogg' />";
                    myobj += "Your browser does not support video";
                    myobj += "</object>";
                    myobj += "</video>";
                }
                else
                {
                    myobj = "<img src='File/BlogFile/blogging.jpg' width='250' height='200'/>";
                }
                Literal1.Text = myobj;

            }