Back to Devexpress

ASPxAutoCompleteBoxBase.ItemTextCellPrepared Event

aspnet-devexpress-dot-web-dot-aspxautocompleteboxbase-616e7d89.md

latest4.4 KB
Original Source

ASPxAutoCompleteBoxBase.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.

The editor’s content is customized using the ASPxAutoCompleteBoxBase.ItemTemplate property.

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

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

Example

The following example illustrates how to customize the appearance of combo 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 customersComboBox_ItemTextCellPrepared(object sender, 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 customersComboBox_ItemRowPrepared(object sender, ListBoxItemRowPreparedEventArgs e) {
    e.Row.ToolTip = GetItemTooltip(e.Item);
}
aspx
<dx:ASPxComboBox ID="customersComboBox" runat="server" DataSourceID="CustomersDataSource" ValueField="CustomerID"
    ValueType="System.String" TextFormatString="{0}" EnableCallbackMode="true" CallbackPageSize="30"
    OnItemTextCellPrepared="customersComboBox_ItemTextCellPrepared" OnItemRowPrepared="customersComboBox_ItemRowPrepared">
    <Columns>
        <dx:ListBoxColumn FieldName="ContactName" Width="150" /> 
        <dx:ListBoxColumn FieldName="CompanyName" Width="200" /> 
        <dx:ListBoxColumn FieldName="Country" />
        <dx:ListBoxColumn FieldName="Phone" /> 
    </Columns>
</dx:ASPxComboBox>
<ef:EntityDataSource runat="server" ID="CustomersDataSource" ContextTypeName="NorthwindContext" 
    EntitySetName="Customers" OrderBy="it.ContactName, it.CompanyName" />

See Also

ItemRowPrepared

Item Appearance CustomizationOnline demo:

ASPxAutoCompleteBoxBase Class

ASPxAutoCompleteBoxBase Members

DevExpress.Web Namespace