C# ListBox.DataBinding方法问题

C# ListBox.DataBinding方法问题,c#,asp.net,listbox,C#,Asp.net,Listbox,关于ListBox.DataBinding方法的问题。我正在加载一个带有DataRows数组对象的列表框,我想检查每个DataRow元素的列值是否为true/false。如果列值为true,则修改当前listBox.ListItem对象的样式。下面是一些示例代码: System.Data.DataRow[] rows = Data.SchoolDetails.Select(filter); lstBox.DataBinding += new EventHandler(lstBox_DataBin

关于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;
}

你不能用列表框真的这么做。也许您应该使用ListView,它支持每个项目的
ItemDataBinding
事件。

使用ListBox不能真正做到这一点。也许您应该使用ListView,它支持每个项目的
ItemDataBinding
事件。

最好的答案可能是您在上面的评论中包含的答案


作为一种替代方法,我可以循环使用DataRow数组并以这种方式执行,然后通过以下操作设置样式:lstBox.Items.Add(new ListItem(“”.Attributes.csssstyle.Add(HtmlTextWriterStyle.FontWeight,“Bold”);。谢谢你的帮助布兰登·迈克尔·亨特


这正是我应该做的。

最好的答案可能就是你在上面评论中提到的答案


作为一种替代方法,我可以循环使用DataRow数组并以这种方式执行,然后通过以下操作设置样式:lstBox.Items.Add(new ListItem(“”.Attributes.csssstyle.Add(HtmlTextWriterStyle.FontWeight,“Bold”);。谢谢你的帮助布兰登·迈克尔·亨特


这正是我要做的。

作为一种替代方法,我可以通过循环DataRow数组并以这种方式执行,然后通过执行以下操作设置样式:lstBox.Items.Add(new ListItem(“”.Attributes.csssStyle.Add(HtmlTextWriterStyle.FontWeight,“Bold”);。感谢您的帮助。作为一种替代方法,我可以循环使用DataRow数组并以这种方式进行操作,然后通过以下操作设置样式:lstBox.Items.Add(new ListItem(“”.Attributes.csssStyle.Add(HtmlTextWriterStyle.FontWeight,“Bold”);。谢谢你的帮助。