Tuesday, December 21, 2010

DropDownList Filling

DropDownList Filling



< asp:DropDownList ID="EmployeeDropDownList" runat="server" Height="16px" Width="155px"

OnSelectedIndexChanged="EmployeeDropDownList_SelectedIndexChanged" AutoPostBack="true"
AppendDataBoundItems="true">

< asp : ListItem Value= " - 1 " > Please Select < / asp : ListItem >
< / asp : DropDownList>




protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindCustomerInfo();
}
}

private void BindCustomerInfo()
{
sqlConnection = new SqlConnection(@"Data Source=DEV2\SQLEXPRESS;Integrated Security=True; Initial Catalog=Linq ");
sqlCommand.CommandText = "Select * from Employee";
sqlCommand.Connection = sqlConnection;

sqlConnection.Open();
EmployeeDropDownList.DataSource = sqlCommand.ExecuteReader();
EmployeeDropDownList.DataTextField = "CompanyName";
EmployeeDropDownList.DataValueField = "CustomerID";
EmployeeDropDownList.DataBind();
}

No comments: