如何在datalist中找到Html控件?

时间:2013-10-28 14:20:42

标签: asp.net datalist

  

我想在 Datalist

中找到 Html 源代码管理
 <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;
    }
}

1 个答案:

答案 0 :(得分:3)

改变这个:

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

对此:

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

它应该有用。

修改

要访问源代码,请执行以下操作:

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