L
lewindha
Hey guys
I'm trying to populate a drop down list with values from a db table.
When I view the page, the drop list is empty. Here is the code:
private void populateClients()
{
string connStr = "left blank for security reasons";
sqlConnection = new SqlConnection(connStr);
sqlConnection.Open();
DataTable t_table = new DataTable();
SqlDataAdapter adapt;
string sql = "SELECT iClientID, cClientName FROM
tblAllocated_ClientID";
sqlSelectCommand1 = new SqlCommand(sql, sqlConnection);
adapt = new SqlDataAdapter(sqlSelectCommand1);
adapt.Fill(t_table);
ClientParm.DataSource = t_table;
ClientParm.DataTextField = "cClientName";
ClientParm.DataValueField = "iClientID";
ClientParm.DataBind();
ClientParm.Items.Add(new ListItem("-Select
Client-", ""));
ClientParm.SelectedValue = "";
}
I created this function and call it from the page_load function like
so:
[code:1:46adb98647]
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
if( !Page.IsPostBack )
{
populateClients();
}
}
catch(Exception ex)
{
}
}
[/code:1:46adb98647]
Can anyone tell me what I'm doing wrong, please?
Thanks
*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
I'm trying to populate a drop down list with values from a db table.
When I view the page, the drop list is empty. Here is the code:
private void populateClients()
{
string connStr = "left blank for security reasons";
sqlConnection = new SqlConnection(connStr);
sqlConnection.Open();
DataTable t_table = new DataTable();
SqlDataAdapter adapt;
string sql = "SELECT iClientID, cClientName FROM
tblAllocated_ClientID";
sqlSelectCommand1 = new SqlCommand(sql, sqlConnection);
adapt = new SqlDataAdapter(sqlSelectCommand1);
adapt.Fill(t_table);
ClientParm.DataSource = t_table;
ClientParm.DataTextField = "cClientName";
ClientParm.DataValueField = "iClientID";
ClientParm.DataBind();
ClientParm.Items.Add(new ListItem("-Select
Client-", ""));
ClientParm.SelectedValue = "";
}
I created this function and call it from the page_load function like
so:
[code:1:46adb98647]
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
if( !Page.IsPostBack )
{
populateClients();
}
}
catch(Exception ex)
{
}
}
[/code:1:46adb98647]
Can anyone tell me what I'm doing wrong, please?
Thanks
*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*