aspnet-devexpress-dot-web-dot-aspxlistbox-40deeb4e.md
Enables the settings of individual rows to be changed.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
public event EventHandler<ListBoxItemRowPreparedEventArgs> ItemRowPrepared
Public Event ItemRowPrepared As EventHandler(Of ListBoxItemRowPreparedEventArgs)
The ItemRowPrepared event's data class is ListBoxItemRowPreparedEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Item | Gets an item object related to the event. |
| Row | Gets the processed row. |
Use the ItemRowPrepared event to change individual rows’ style settings (CssClass, Tooltip, control styles). The ItemRowPrepared event is raised for each row within the editor’s list.
The processed row is identified by the ListBoxItemRowPreparedEventArgs.Row property.
To set an attribute to a processed item, use the client SetItemAttribute(index, attributeName, attributeValue) method.
function OnClick(s, e) {
listBox.SetItemAttribute(5, "your_attribute_name", "attribute_value");
}
The following example illustrates how to customize the appearance of list box items.
string GetItemTooltip(ListEditItem item)
{
return string.Format("Country: {0}\r\nCity: {1} \r\nAddress: {2}",
item.GetFieldValue("Country"), item.GetFieldValue("City"), item.GetFieldValue("Address"));
}
protected void ASPxListBox1_ItemTextCellPrepared(object sender, DevExpress.Web.ListBoxItemTextCellPreparedEventArgs e)
{
if (e.Column.FieldName == "ContactName") {
string contactTitle = e.Item.GetFieldValue("ContactTitle").ToString();
if (contactTitle == "Owner")
{
e.TextCell.CssClass += " owner";
e.TextCell.ToolTip = "Owner";
}
}
if (e.Column.FieldName == "Phone")
e.TextCell.CssClass += " phone";
}
protected void ASPxListBox1_ItemRowPrepared(object sender, DevExpress.Web.ListBoxItemRowPreparedEventArgs e)
{
e.Row.ToolTip = GetItemTooltip(e.Item);
}
<head runat="server">
<title></title>
<style type="text/css">
.phone {
color: #9C0006;
font-style: italic;
}
.owner {
color: #006100;
background-color: #C6EFCE;
font-weight: bold;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxListBox ID="ASPxListBox1" runat="server" OnItemTextCellPrepared="ASPxListBox1_ItemTextCellPrepared"
OnItemRowPrepared="ASPxListBox1_ItemRowPrepared" DataSourceID="SqlDataSource1">
<Columns>
<dx:ListBoxColumn FieldName="ContactName" />
<dx:ListBoxColumn FieldName="CompanyName" />
<dx:ListBoxColumn FieldName="Phone" />
</Columns>
</dx:ASPxListBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=|DataDirectory|\nwind.mdb;Persist Security Info=True" ProviderName="System.Data.OleDb"
SelectCommand="SELECT [CompanyName], [ContactName], [ContactTitle], [Address], [City], [Region], [Country], [Phone] FROM [Customers]"></asp:SqlDataSource>
</div>
</form>
</body>
See Also