簡體   English   中英

ListBox.DataBinding方法問題

[英]ListBox.DataBinding Method Question

有關ListBox.DataBinding方法的問題。 我正在加載帶有DataRows數組對象的列表框,我想檢查每個DataRow元素的列值是否為true / false。 如果該列的值為true,則修改當前listBox.ListItem對象的樣式。 下面是一些示例代碼:

System.Data.DataRow[] rows = Data.SchoolDetails.Select(filter);
lstBox.DataBinding += new EventHandler(lstBox_DataBinding);
lstBox.DataSource = rows;
lstBox.DataTExtField = "Value";
lstBox.DataValueField = "ValueCode";
lstBox.DataBind();

static void lstBox_DataBinding(object sender, EventArgs e)
{
  ListBox l = (ListBox) sender;
}

您真的不能使用ListBox做到這一點。 也許您應該使用ListView,它支持每個項目的ItemDataBinding事件。

最好的答案可能是您包含在上面的評論中的答案。

作為替代方案,我可以遍歷DataRow數組並以此方式進行操作,並通過以下方式設置樣式:lstBox.Items.Add(new ListItem(“”)。Attributes.CssStyle.Add(HtmlTextWriterStyle.FontWeight,“ Bold “));。 感謝您的幫助。 –布蘭登·邁克爾·亨特

那正是我要做的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM