Back to Devexpress

ASPxListBox.ItemTextCellPrepared Event

aspnet-devexpress-dot-web-dot-aspxlistbox-38776d6d.md

latest4.6 KB
Original Source

ASPxListBox.ItemTextCellPrepared Event

Occurs on the server side before a text cell has been rendered.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event EventHandler<ListBoxItemTextCellPreparedEventArgs> ItemTextCellPrepared
vb
Public Event ItemTextCellPrepared As EventHandler(Of ListBoxItemTextCellPreparedEventArgs)

Event Data

The ItemTextCellPrepared event's data class is ListBoxItemTextCellPreparedEventArgs. The following properties provide information specific to this event:

PropertyDescription
ColumnGets the column that owns a cell that is about to be processed.
ItemGets an item object related to the event.
TextCellGets the currently processed cell of the editor.

Remarks

Write a ItemTextCellPrepared event handler to customize the cell appearance (CssClass, Tooltip, control styles) before it is rendered.

To set an attribute to a text cell, use the client SetItemTextCellAttribute(itemIndex, textCellIndex, attributeName, attributeValue) method.

js
function OnClick(s, e) {
    listBox.SetItemTextCellAttribute(5, 1, "your_attribute_name", "attribute_value");
}

Example

The following example illustrates how to customize the appearance of list box items.

csharp
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);
}
aspx
<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

ItemRowPrepared

Item Appearance CustomizationOnline demo:

ASPxListBox Class

ASPxListBox Members

DevExpress.Web Namespace