Question

I want to find the Html source control in Datalist

 <asp:DataList ID="DL_Media" runat="server" 
                        onitemdatabound="DL_Media_ItemDataBound">
                        <ItemTemplate>
                            <video width="215" height="160" runat="server"  id="vd" controls>
                            <source src='<%# Eval("Media_File")%>' type="video/ogg" runat="server" id="source"></source>
                            </video>
                        </ItemTemplate>
                    </asp:DataList>



 protected void DL_Media_ItemDataBound(object sender, DataListItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        HtmlGenericControl video = e.Item.FindControl("source") as HtmlGenericControl;
    }
}
Was it helpful?

Solution

Change this:

HtmlGenericControl video = e.Item.FindControl("source") as HtmlGenericControl;

To this:

HtmlGenericControl video = e.Item.FindControl("vd") as HtmlGenericControl;

And it should work.

EDIT:

To access the source do this:

HtmlGenericControl source= e.Item.FindControl("source") as HtmlGenericControl;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top