在 ASP.NET WebForms 中,DataList 綁定數據源後,需在頁面 <% %> 代碼塊內根據當前行的某字段值動態控制 HTML 輸出。
推薦使用 DataBinder.Eval(Container.DataItem, "字段名") 或直接轉型 Container.DataItem 獲取強類型對象。
<%# DataBinder.Eval(Container.DataItem, "FieldName") %>
或在 <% %> 中:
<%
var item = (MyEntity)Container.DataItem;
if (item.Status == 1) { %>
<span>顯示內容</span>
<% } %>
詳細案例可參考:CSDN 博客示例