[英]If a controls datasource has 0 items does it still databind and is there any performance gain by not calling databind if the count is 0?
如果我有一個我想要隱藏的轉發器,如果有0個項目我很好奇。 就性能而言,我應該這樣做:
if (data.Count > 0)
{
rpt.DataSource = data;
rpt.DataBind();
rpt.Visible = true;
}
else
{
rpt.Visible = false;
}
或者只是這樣做是好的:
rpt.DataSource = data;
rpt.DataBind();
rpt.Visible = data.Count() > 0;
謝謝!
是的,您可以使用空數據源進行綁定。 只要DataSource不為null,就可以將其綁定到您的控件。
它做了一個數據綁定,但沒有顯示任何東西。 例如,如果您有一個datagrid,並嘗試將somme數據與空數據源綁定,則它將不會顯示任何內容,除非您已將datagrid的EmptyDataText屬性設置為某些文本。 在這種情況下,它將顯示此文本
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.