How To Create Multi Column Dropdownlist

This post will show how to create the multi-column dropdown list using your server-side code, use the \u00A0 character as your padding character. Then, create calculated columns in your data table to set as the text field for the dropdownlist.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MultiCoulmn.aspx.cs" Inherits="MultiCoulmn" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
 <form id="form1" runat="server">
     <asp:DropDownList ID="ddlUser" runat="server">
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MultiCoulmn : System.Web.UI.Page
   protected void Page_Load(object sender, EventArgs e)
       List<Friend> friends = GetFriends();
       foreach (Friend f in friends)

           string text = string.Format("{0}|{1}", f.Name.PadRight(10, '\u00A0'), f.Description.PadRight(10,'\u00A0'));
           ddlUser.Items.Add(new ListItem(text, f.Id.ToString()));


   public List<Friend> GetFriends()

       List<Friend> users = new List<Friend>();
       users.Add(new Friend("Xyz", "Coder"));
       users.Add(new Friend("Abc", "Writer"));
       users.Add(new Friend("Charles", "Poet"));
       return users;

public class Friend

   public Friend(string name, string description)

       _name = name;

       _description = description;

       _id = Guid.NewGuid().ToString();

   private string _id;
   public string Id

       get { return _id; }

       set { _id = value; }

   private string _name;
   public string Name
       get { return _name; }
       set { _name = value; }
   private string _description;
   public string Description
       get { return _description; }
       set { _description = value; }

Next Post Previous Post
No Comment
Add Comment
comment url