Reputation: 1899
I did my code to find HTML control " Source" and I want to check if "Src" attribute have value or not , I tried to add " inner text" but it return NULL .
<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("vd") as HtmlGenericControl;
HtmlGenericControl source = e.Item.FindControl("source") as HtmlGenericControl;
if (source != null)
{
string x = "~/";
string y = "";
if (source.InnerText == x)
{
video.InnerText.Replace(x, y);
DL_Media.DataBind();
}
}
}
Upvotes: 0
Views: 932
Reputation: 7943
Try this:
HtmlGenericControl source= e.Item.FindControl("source") as HtmlGenericControl;
string src = source.Attributes["src"].ToString();
Source: How to: Read HTML Attributes for Controls in Web Forms Pages.
Upvotes: 1