Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

GridSearchBoxTemplateContext.SearchText Property

Specifies the search text.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
public string SearchText { get; set; }

#Property Value

Type Description
String

The search text.

#Remarks

When the ShowSearchBox property is set to true, the Grid displays the search box. Users can type text in the box editor to filter and highlight data.

The SearchBoxTemplate property allows you to specify custom content for the search box. In the template, use the context parameter to access the SearchText property, which specifies the search text.

The following code snippet uses the DxSpinEdit<T> component to search for numbers in the Grid.

razor
<DxGrid Data="Products" ShowSearchBox="true">
    <Columns>
        <DxGridDataColumn FieldName="ProductName" />
        <DxGridDataColumn FieldName="CategoryId" Caption="Category" />
        <DxGridDataColumn FieldName="UnitPrice" DisplayFormat="c" />
    </Columns>
    <SearchBoxTemplate> 
        <DxSpinEdit Value="GetSpinEditValue(context.SearchText)"
                    ValueChanged="(int? v) => context.SearchText = v.ToString()"
                    ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto" />
    </SearchBoxTemplate>
</DxGrid>
@code {
    int? GetSpinEditValue(string searchText) {
        if(string.IsNullOrEmpty(searchText))
            return null;
        return Convert.ToInt32(searchText);
    }
}

Search Box Template

For more information about search in the Grid component, refer to the following topic: Search Box in Blazor Grid.

See Also