Previous | Home | Next |
using System.Collections.Generic you can customize your dropdownlist items.
.CS code
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Collections.Generic; public partial class dropdatain_dictonary : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Dictionary<int, string> dicRel = new Dictionary<int, string>(); dicRel.Add(1, "Father"); dicRel.Add(2, "Mother"); dicRel.Add(3, "Brother"); dicRel.Add(4, "Sister"); dicRel.Add(5, "Others"); ddlRelatives.DataSource = dicRel; ddlRelatives.DataTextField = "Value"; ddlRelatives.DataValueField = "Key"; ddlRelatives.DataBind(); } }
.ASPX code
<%@ Page Language="C#" AutoEventWireup="true" Codevirtual="dropdatain dictonary.aspx.cs" Inherits="dropdatain_dictonary" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="ddlRelatives" runat="server"> </asp:DropDownList> </div> </form> </body> </html>
Output:

Previous | Home | Next |