2013-10-28 67 views
0

我想找到的Html源控制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; 
    } 
} 

回答

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;