I assume you are talking about an Asp.net implementation.
If that is so, here I have done a sample implementation for you. This shows a
DropDownList
control populated with some dummy data. When you change the selection of the
DropDownList
, system shows the selected item's data in a Label. Setting the DropDownList's
AutoPostback="true"
and setting an Event handler for
SelectedIndexChanged
lets you get the selected data in the CodeBehind and thus display detail properties in other controls.
The Aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 AutoPostBack="true" ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<br />
You selected : <asp:Label ID="txtName" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
And, the CodeBehind:
using System;
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 _Default : System.Web.UI.Page
{
class Person
{
public int Id
{
get;
set;
}
public string Name
{
get;
set;
}
public Person(int Id, string Name)
{
this.Id = Id;
this.Name = Name;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PopulateData();
}
}
private void PopulateData()
{
List<Person> persons = new List<Person> { new Person(1, "Shubho"), new Person(2, "John"), new Person(3, "Tommy") };
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "Id";
DropDownList1.DataSource = persons;
DropDownList1.SelectedIndex = 0;
DropDownList1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
int Id = Convert.ToInt32(DropDownList1.SelectedValue);
Person selectedPerson = GetPerson(Id);
txtName.Text = selectedPerson.Name;
}
private Person GetPerson(int Id)
{
List<Person> persons = new List<Person> { new Person(1, "Shubho"), new Person(2, "John"), new Person(3, "Tommy") };
foreach (Person person in persons)
{
if (person.Id == Id) return person;
}
return null;
}
}