ListBox.DataBinding Method Question
Question about the ListBox.DataBinding method. I'm loading a listbox with a DataRows array object and I want to check for each DataRow element a column value if its true/false. If the column value is true, then modify the style for the current listBox.ListItem object. Below is some sample code.:
System.Data.DataRow[] rows = Data.SchoolDetails.Select(filter);
lstBox.DataBinding += new EventHandle开发者_C百科r(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;
}
You can't really do that with a ListBox. Maybe you should use ListView, which supports an ItemDataBinding
event for each item.
The best answer is probably the one you included in the comment above.
As an alternative I can just loop through the DataRow array and do it that way, and set the style by doing this: lstBox.Items.Add(new ListItem("").Attributes.CssStyle.Add(HtmlTextWriterStyle.FontWeight, "Bold"));. Thanks for hte help. – Brandon Michael Hunter
That is exactly how I'd do it.
精彩评论