DataList项模板中的div在后台得到方法

DataList项模板中的div(runat=server),在后台可得到该div,并且该div的类型为  System.Web.UI.HtmlControls.HtmlGenericControl


例如,前台为


 <asp:DataList ID="dlComInfo" runat="server" CssClass="dlComInfo" 
        DataSourceID="SqlDataSource2" onitemcommand="dlComInfo_ItemCommand" 
        onitemdatabound="dlComInfo_ItemDataBound">
        <ItemTemplate>
          <div>
            <div id="buyDiv" runat="server">
           </div>
         </div>
</ItemTemplate>
 </asp:DataList>


后台得到div的代码


 protected void dlComInfo_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {           
                (e.Item.FindControl("buyDiv") as System.Web.UI.HtmlControls.HtmlGenericControl).Visible = true;          
        }
    }

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页