//Visit http://www.laptrinhdotnet.com for more ASP.NET Tutorials
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Diagnostics;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace UsingBootstrapChangeDropdownlistStyle
{
public partial class _Default : System.Web.UI.Page
{
#region"Bind Data"
private voidPopulateDropdownlist()
{
DataTable objBind = newDataTable();
int CategoryID = -1;
string CategoryName = "";
string TotalProducts = "";
objBind = BindData();
if (objBind != null)
{
if (objBind.Rows.Count > 0)
{
for(int i = 0; i <= objBind.Rows.Count - 1; i++)
{
if (objBind.Rows[i]["CategoryID"] != null)
{
CategoryID =Convert.ToInt32(objBind.Rows[i]["CategoryID"]);
}
if (objBind.Rows[i]["CategoryName"] != null)
{
CategoryName = objBind.Rows[i]["CategoryName"].ToString();
}
if(objBind.Rows[i]["TotalProducts"] != null)
{
TotalProducts = objBind.Rows[i]["TotalProducts"].ToString();
}
ddlObject.Items.Add(new ListItem(CategoryName + " (" + TotalProducts + ")", CategoryID.ToString()));
}
}
}
}
private DataTableBindData()
{
SqlDataProvider objSQL = newSqlDataProvider();
DataTable objBind = objSQL.FillTable("Select Products.CategoryID, Categories.CategoryName, COUNT(Products.ProductID) AS TotalProducts FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID GROUP BY Products.CategoryID, Categories.CategoryName ORDER BY Categories.CategoryName");
return objBind;
}
#endregion
#region"Event Handles"
protected voidPage_Load(object sender, System.EventArgs e)
{
try
{
if(!IsPostBack)
{
PopulateDropdownlist();
}
}
catch
{
}
}
#endregion
}
}