locked
How do i hid video player control in Formview if video or image content doesn't exist? RRS feed

  • Question

  • User-625131191 posted

    I have a FormView that displays user contents, both data, image and video. But if user content doesn't contain video content in database the video handle is displayed on FormView, so how do i hid video or image control if image or video doesn't exist?.

    html

     <asp:FormView ID="FormView1" runat="server"  OnDataBound="FormView1_DataBound">
                            <ItemTemplate>
                                  <asp:Image ID="Image3vi" Text='<%#Eval("ImageName1")%>' runat="server" src='<%#getSRCDD(Container.DataItem)%>  ' Width="100%"  class="imagepost img-rounded" alt=""  ImageUrl='<%# ("../UserImage/") %>'/>
                                  <video id="my-player" class="video-js" controls="controls" preload="auto"  data-setup="{}" style="width:100%; height:323px">
        <source src="<%# Eval("Path") %>" type="video/mp4">
                        <source src="<%# Eval("Path") %>" type="video/ogg">
                        <source src="<%# Eval("Path") %>" type="video/webm" >
        <div class="vjs-no-js">
          To view this video please enable JavaScript, and consider upgrading to a web browser that
          <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
        </div>
      </video>
                            </ItemTemplate>
                        </asp:FormView> 
    protected void FormView1_DataBound(object sender, EventArgs e)
        {
    }

    Saturday, March 10, 2018 1:24 PM

Answers

  • User-1838255255 posted

    Hi Skyformat48,

    According to your description and code, i make a sample through your needs, please check the following sample code:

    Sample Code:

    <asp:FormView ID="FormView1" runat="server" OnDataBound="FormView1_DataBound">
                    <ItemTemplate>
                        <table border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td>ID:
                                </td>
                                <td>
                                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>Name:
                                </td>
                                <td>
                                    <%# Eval("Name") %>
                                </td>
                            </tr>
                            <tr>
                                <td>Description:
                                </td>
                                <td>
                                    <%# Eval("Description") %>
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
    </asp:FormView>
    
    protected void Page_Load(object sender, EventArgs e)
            {
                if (!this.IsPostBack)
                {
                    DataTable dt = new DataTable();
                    dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
                        new DataColumn("Name", typeof(string)),
                        new DataColumn("Description",typeof(string)) });
                    dt.Rows.Add(1, "John Hammond", "Works as a scientist in USA.");
                    FormView1.DataSource = dt;
                    FormView1.DataBind();
                }
            }
    
            protected void FormView1_DataBound(object sender, EventArgs e)
            {
    
                Label Label4 = (Label)FormView1.FindControl("Label1");
                string label4 = Label4.Text;
                if (label4 == "1")
                {
                    Label4.Style.Add("display", "none");
                }
                else
                {
                    // do nothing
                }
            }

    Result:

     

    Best Regards,

    Eric Du 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 12, 2018 10:07 AM