Easiest Way to Create a Multicolumn ComboBox in Blazor | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (180).NET Core  (28).NET MAUI  (225)Angular  (113)ASP.NET  (49)ASP.NET Core  (81)ASP.NET MVC  (87)Azure  (41)Black Friday Deal  (1)Blazor  (234)BoldSign  (14)DocIO  (24)Essential JS 2  (110)Essential Studio  (199)File Formats  (72)Flutter  (136)JavaScript  (226)Microsoft  (121)PDF  (83)Python  (1)React  (105)Streamlit  (1)Succinctly series  (131)Syncfusion  (962)TypeScript  (33)Uno Platform  (3)UWP  (3)Vue  (46)Webinar  (53)Windows Forms  (59)WinUI  (72)WPF  (163)Xamarin  (159)XlsIO  (38)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (10)Business intelligence  (55)Button  (4)C#  (163)Chart  (145)Chart of the week  (57)Cloud  (15)Company  (440)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (73)Development  (677)Doc  (7)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (7)Essential Tools  (13)Excel  (43)Extensions  (23)File Manager  (7)Gantt  (21)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (521)Mobile MVC  (9)OLAP server  (2)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (45)Performance  (13)PHP  (2)PivotGrid  (5)Predictive Analytics  (6)Report Server  (3)Reporting  (8)Reporting / Back Office  (9)Rich Text Editor  (12)Road Map  (12)Scheduler  (54)Security  (5)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (32)Solution Services  (4)Spreadsheet  (11)SQL  (15)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (113)UI  (403)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (625)What's new  (339)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Easiest Way to Create a Multicolumn ComboBox in Blazor

Easiest Way to Create a Multicolumn ComboBox in Blazor

In this blog post, we will look at the creation of a multicolumn combo box component in Blazor. You will learn how to configure and bind the data in the Syncfusion Blazor ComboBox component to make it display multiple columns of data.

What is a multicolumn combo box?

A standard ComboBox will display a list of items in a single column. So, only a single piece of information about the item can be displayed in an instance.

Example: Displaying a list of product names.

But a multicolumn combo box displays a list of items in multiple columns like in a grid view. So, it is used to display more information regarding an item in a single list.

Example: Let’s suppose a user wants to select a product based on its unit price and the units in stock. In that scenario, they want a multicolumn combo box. This provides a quick and detailed glance at all relevant information about a product. We may also display more information, like units on order and discounts, with multicolumn view support.

Let’s get started creating a multicolumn combo box component in Blazor.


Create a Blazor WebAssembly application

In this example, we are going to display the following information regarding the products:

  • Product ID
  • Name
  • Unit price
  • Units in stock
  • Units on order

Step 1: Create a Blazor WebAssembly app and add the required models and controller classes. We will have three project files created inside this solution:

  • Client: Contains the client-side code and the pages that will be rendered on the browser.
  • Server: Contains the server-side code, such as DB-related operations and the web API.
  • Shared: Contains the shared code that can be accessed by both client and server.

Step 2: Now, create a new model class file inside the Shared project with the name Product. In this class file, we are going to access the Client and Server projects for data binding.

    public class Product
        public int? ProductID { get; set; }
        public string ProductName { get; set; }
        public int? SupplierID { get; set; }
        public double? UnitPrice { get; set; }
        public int UnitsInStock { get; set; }
        public int UnitsOnOrder { get; set; }

Step 3: After creating the model class, add the web API controller to the Server project with the name ProductController. In this controller file, I have included the Get methods to generate appropriate data, which you can reference from this GitHub repository.

    public class ProductController : ControllerBase
        // GET: api/Product
        public IEnumerable Get()
            List ProductsList = new List
                new Product{ProductID=1, ProductName="Chai", UnitPrice=18.0000, SupplierID=1, UnitsInStock=39, UnitsOnOrder=0 },
                new Product {ProductID=2, ProductName="Chang", UnitPrice=19.000, SupplierID=2, UnitsInStock=17, UnitsOnOrder=49},
                new Product{ProductID=10, ProductName="Queso Manchego La Pastora", UnitPrice=26.000, SupplierID=1, UnitsInStock=12, UnitsOnOrder=20}
            return ProductsList;

Adding ComboBox and configuring multiple columns

To achieve multicolumn support in ComboBox, we should add the Syncfusion Blazor ComboBox component to the created Blazor WebAssembly app.

Step 1: Add the following code example in the index.razor file to create a simple ComboBox along with product data binding.

<SfComboBox TValue="string" TItem="Product" PopupWidth="700px" DataSource="@_productsList" PopupHeight="400px" Placeholder="Select a Product">
    <ComboBoxFieldSettings Text="ProductName" Value="ProductID"></ComboBoxFieldSettings>

Step 2: Now, we need to display the pop-up list item in multicolumn view to show more information when the user opens the pop-up of the ComboBox. To do so, use the item template to display column data in table view and the header template to display the table of column names.

<SfComboBox TValue="string" TItem="Product" PopupWidth="700px" DataSource="@_productsList" PopupHeight="400px" CssClass="e-multi-column" Placeholder="Select a Product">
   <ComboBoxTemplates TItem="Product">
         <table><tr><th class="e-text-center">Product ID</th><th width="240px">Product Name</th><th>Unit Price</th><th>Units In Stock</th><th>Units On Order</th></tr></table>
         <table><tbody><tr><td class="e-text-center">@((context as Product).ProductID)</td><td width="240px">@((context as Product).ProductName)</td><td>@((context as Product).UnitPrice)</td><td>@((context as Product).UnitsInStock)</td><td>@((context as Product).UnitsOnOrder)</td></tr> </tbody></table>
   <ComboBoxFieldSettings Text="ProductName" Value="ProductID"></ComboBoxFieldSettings>

Step 3: We have provided the multicolumn style class in the built-in Syncfusion Blazor theme files. Here, we need to give the multicolumn root class name “e-multi-column” in the CssClass API, like in the following  code example.

<SfComboBox CssClass="e-multi-column" TValue="string" TItem="Product" DataSource="@_productsList">
    <ComboBoxFieldSettings Text="ProductName" Value="ProductID"></ComboBoxFieldSettings>

Step 4: Next, get the data from the product service and bind it to the ComboBox DataSource API with the OnInitializedAsync method.


    private Product[] _productsList;

    protected override async Task OnInitializedAsync()
        _productsList = await Http.GetJsonAsync<Product[]>("Product");

After executing the previous code examples, we’ll get output like the following screenshot. See how it displays the ComboBox list items information in the multicolumn view.
output of Multicolumn ComboBox

Display customized information

Now, we can display the custom text alignment in each column using a built-in class, like in the following code example:

  • e-text-center: Displays the text in center of the column.
  • e-text-right: Displays the text in right side of the column.
  • e-text-left: Displays the text in left side of the column.
    <table><tr><th class="e-text-center">Product ID</th></tr></table>
     <table><tbody><tr><td class="e-text-center">@((context as Product).ProductID)</td></tr> </tbody></table>


I hope you can now add and display a multicolumn view in the ComboBox drop-down. You can easily customize the pop-up and list the items using the template option, which you can learn more about from this demo.You can download the complete source code of this example from the GitHub repository.

Try our Blazor ComboBox component by downloading a free 30-day trial or see our NuGet package. Feel free to have a look at our online examples and documentation to explore other available features.

If you have any questions, please let us know in the comments section below. You can also contact us through our support forum, Direct-Trac, or feedback portal.  We are always happy to assist you!


Share this post:

Comments (5)

Really looking forward to doing the example – but the code link to GitHub does not work

Hello D E,

Thank you for your feedback, now the GitHub sample is accessible.

Saravanan G

This is really, really nice! Any chance that all columns are searchable like the AutoComplete?

Hello Anthony,

Yes, we can search text in all columns with the filtering feature. You can enable the AllowFiltering property and make custom filtering with the Filtering event.

Please find the below update sample – https://github.com/SyncfusionExamples/blazor-multi-column-combobox

Saravanan G

In .net 8 it is throwing error due to context, so by declaring it with ItemTemplate it solved the issue.

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed