<%# ... %>,需呼叫 DataBind() 觸發運算。ListControl 衍生,固定 UI 重複顯示集合。GridView 等組合控件,彈性模板、分頁、排序。預期用法:
star.DataSource = dt;
star.DataTextField = "Comment";
star.DataValueField = "Score";
star.DataBind();
頁面標記 <cc:Star Score='4' Comment='<%#DateTime.Now%>' /> 若不呼叫 Page.DataBind() 或 star.DataBind(),運算式不會執行。Page.DataBind() 會遞歸呼叫所有子控件 DataBind(),適合多處運算式。
web.config 設 <compilation debug="true" tempDirectory="c:\web"> 查看產生的暫存類別,理解綁定運算式如何編譯為代碼。