Thank you for your question. You can follow the bellow code.
public void PopulateGCSCompany(ListBox list, String connectionString)
{
StringBuilder sbQuery = new StringBuilder();
sbQuery.AppendLine(" SELECT ");
sbQuery.AppendLine(" [GCSCompanyId],[CompanyName] ");
sbQuery.AppendLine(" FROM [GCSCompany] ");
sbQuery.AppendLine(" ORDER BY [CompanyName] ASC ");
using (SqlConnection conn = new SqlConnection(connectionString))
{
DataTable companyDataTable = new DataTable();
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sbQuery.ToString(), conn);
sqlDataAdapter.Fill(companyDataTable);
list.DataValueField = "GCSCompanyId";
list.DataTextField = "CompanyName";
list.DataSource = companyDataTable;
list.DataBind();
list.Items.Insert(0, new ListItem("", "0"));
}
}
Thanks,
Mamun