ASP.NET MVC ComboBox - Grid-Like Multi-Columns with Icons


The items of the ComboBox can be displayed in a grid-like structure. By using item templates, you can display as many columns of data as you wish. A header and a footer can also be displayed, to make the list with items look even more like a grid view.

You can display any data field in the item template, by using the ComboBoxItem.DataItem object.

When using this approach to display items, your end users will still benefit from the other features of the ComboBox: autocomplete, load on demand, virtual scrolling, filtering, etc.

This sample shows how easy it is to add images for items in the grid-like structure.
View - Aspx

   <% Html.Obout(new ComboBox("ComboBox1")
    {
        Width = 200,
        Height = 250,
        MenuWidth = 400,
        HeaderTemplate = new OboutMvcTemplate<ComboBoxHeaderTemplateContainerInfo>((info) =>
                {%>
                    <div class="header c1"> </div>
	                <div class="header c2">PRODUCT NAME</div>
	                <div class="header c3">PRICE</div>
                <%}),
            ItemTemplate = new OboutMvcTemplate<ComboBoxItem>((item) =>
                {%>
                    <div class="item c1"><img src="/Content/Resources/sample-product.jpg" alt="" /></div>
	                <div class="item c2"><%= ((oboutSuite.Product)item.DataItem).ProductName%></div>
	                <div class="item c3"><%= string.Format("{0:C2}", ((oboutSuite.Product)item.DataItem).UnitPrice)%>
                    </div>
                <%}),
            FooterTemplate = new OboutMvcTemplate<ComboBoxFooterTemplateContainerInfo>((data) =>
                {%>
                    Displaying <%= data.ItemsCount %> items.
                <%})
      
        }); %>
    
View - Razor

    <% Html.Obout(new ComboBox("ComboBox1")
    {
        Width = 200,
        Height = 250,
        MenuWidth = 400,
        HeaderTemplate = new OboutMvcTemplate<ComboBoxHeaderTemplateContainerInfo>(
            @:<div class="header c1"> </div>
	            <div class="header c2">PRODUCT NAME</div>
	            <div class="header c3">PRICE</div>
            ),
        ItemTemplate = new OboutMvcTemplate<ComboBoxItem>(
            @:<div class="item c1"><img src="/Content/Resources/sample-product.jpg" alt="" /></div>
	            <div class="item c2">@(((oboutSuite.Product)item.DataItem).ProductName)</div>
	            <div class="item c3">@(string.Format("{0:C2}", ((oboutSuite.Product)item.DataItem).UnitPrice))
                </div>
            ),
        FooterTemplate = new OboutMvcTemplate<ComboBoxFooterTemplateContainerInfo>(
            @:Displaying @(item.ItemsCount) items.
            )
        }); %>
    
CSS
 
    .ob_iCboICBC li, .ob_iCboICBC li div.b, .ob_iCboICBC li.ih i
    {
        height: 50px !important;
        line-height: 50px !important;
    }
        
    .ob_iCboICBC li div.b img, .ob_iCboICBC li div img
    {
        margin-top: 3px !important;
        height: 45px !important;
    }
        
    .ob_iCboICBC li.ih, .ob_iCboICBC li.ih div.b, .ob_iCboICBC li.ih i
    {
        background-image: none !important;
        background-color: #CEF0F9 !important;
    }
        
    .item
    {
        position: relative !important;
        display:-moz-inline-stack;
        display:inline-block;
        zoom:1;
        *display:inline;
        overflow: hidden;
        white-space: nowrap;
        height: 50px;
    }
        
    .header
    {
        margin-left: 2px;
    }
   
    .c1
    {
        width: 45px;
    }
        
    .c2
    {
        margin-left: 10px;
        width: 180px;
    }
        
    .c3
    {
        margin-left: 10px;
        width: 90px;
    }
    
obout.com 
obout.com Home 
News 
ASP.NET MVC ComboBox Home   
ASP.NET MVC ComboBox Home 
Examples - 53
Appearance - 1 
Live Styles 
Autocomplete & Filtering - 2 
Autocomplete  
Filtering  
Load on Demand - 7 
Load Items on Demand 
Load Items on Demand with Paging  
Virtual Scrolling  
Initial Text  
Initial Text on Client-Side  
Load Items on Button Click  
Load Items with MinChars  
Multi-Columns - 4 
Grid-like Multi-Columns  
Grid-like Multi-Columns & Tooltips  
Multiple Rows and Columns  
State Selector  
Items with Icons - 3 
Items with Icons  
Grid-like Multi-Columns with Icons  
Multiple Rows and Columns with Icons  
Templates - 3 
Item Templates  
Header Templates  
Populating with Data - 1 
Populate with Data  
Item Selection - 6 
Single Item Selection  
Multi Item Selection  
Get Selected Item  
Get Selected Items  
Set Selected Item  
Set Selected Items  
Mode - 2 
ComboBox  
TextBox  
Master/Detail - 3 
Master/Detail  
Unlimited Detail Levels  
Cascading ComboBoxes  
Integration - 3 
Items with ASP.NET CheckBoxes  
Items with Obout CheckBoxes  
RadioButtons inside ComboBox  
Settings - 8 
AllowCustomText  
AllowEdit  
AutoPostback  
AutoValidate  
Height  
MenuWidth  
OpenOnFocus  
Width  
Server-Side API - 2 
Server-Side Events  
Enable / Disable  
Client-Side API - 8 
Client-Side Events  
Add / Remove Items  
Add Multi-Column Items  
Enable / Disable  
Get Selected Item  
Reset Selection  
Select / Deselect All Items  
Move Items  
Documentation - 1 
ChangeLog