Wednesday, August 13, 2014

How to create dropdownlist with filter and multiselect.

In this article i have post for dropdownlist with multiple selection with filter using bootstrap.

this example also help for ASP.NET application. 
Add thease scripts and css on your page.
  
    
    
    
    
    
    


Add this div on your page.
  
 
Add this code in your c#(.cs) page.
 

 protected void Page_Load(object sender, EventArgs e)
 {
     ddlProduct.Attributes["multiple"] = "multiple";
     if (!Page.IsPostBack)
     {
        BindData();
     }
}

private void BindData()
{
    List product =new List();
    product.Add(new ProductDetails { Id = 1, Name = "Books" });
    product.Add(new ProductDetails { Id = 2, Name = "Shoes" });
    product.Add(new ProductDetails { Id = 3, Name = "Computer" });
    product.Add(new ProductDetails { Id = 4, Name = "Pen" });
    product.Add(new ProductDetails { Id = 5, Name = "LCD" });
    product.Add(new ProductDetails { Id = 6, Name = "TV" });
    product.Add(new ProductDetails { Id = 7, Name = "Laptop" });
    product.Add(new ProductDetails { Id = 8, Name = "Bags" });
    ddlProduct.DataSource = product;
    ddlProduct.DataTextField = "Name";
    ddlProduct.DataValueField = "Id";
    ddlProduct.DataBind();
}

public class ProductDetails
{
    public int Id { get; set; }

    public string Name { get; set; }
}

Preview Of this example.