Bind drop-down to table - Please urgent

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can somebody please tell me how to bind a drop-down (states) to a table
programmatically? I have the connection information in the procedure and I
am not using the connection objects in the GUI interface.

Thanks,


Antonio
 
What have you tried that doesn't work ? Defining the DataSource and calling
DataBind if ASP.NET should be enough.

You may want also to post in a windows forms or an ASP.NET group so that we
know which kind of UI you are using...
 
This is what I tried:

//binding for the State drop-down
string strTable = "GEM.states";
string strWhere = "";

if (IsPostBack)
{
strWhere = " WHERE stateid=" + lstState.SelectedItem.Value;
}
string strState = "SELECT *, (statename, stateprefix) as State FROM " +
strTable + strWhere + " ORDER BY stateprefix";

adapter.Fill(ds,strTable);
lstState.DataSource = ds.Tables[strTable].DefaultView;
lstState.DataBind();
 
1) Which DB are you using the "(a,b) as c" syntax looks a bit weird to me
2) I would define DataTextField and DataValueField.
3) Have you checked that you have actually returned rows ?
4 ) My approach would be to bind with a table created from scratch to find
out first if the problem is UI side or data side. If you still see nothign
but have data, it could be that you rebind in some other event (in which
event do you have this ?).

Good luck.

--
Patrice

Antonio said:
This is what I tried:

//binding for the State drop-down
string strTable = "GEM.states";
string strWhere = "";

if (IsPostBack)
{
strWhere = " WHERE stateid=" + lstState.SelectedItem.Value;
}
string strState = "SELECT *, (statename, stateprefix) as State FROM " +
strTable + strWhere + " ORDER BY stateprefix";

adapter.Fill(ds,strTable);
lstState.DataSource = ds.Tables[strTable].DefaultView;
lstState.DataBind();

Patrice said:
What have you tried that doesn't work ? Defining the DataSource and
calling
DataBind if ASP.NET should be enough.

You may want also to post in a windows forms or an ASP.NET group so that
we
know which kind of UI you are using...
 
Patrice, I have it in the Page_Load procedure.
1) I changed it to SELECT *, (statename, stateprefix) as State FROM " +
strTable + strWhere + " ORDER BY stateprefix";
2) are you talking about the drop-down properties?
3) Yes.

Patrice said:
1) Which DB are you using the "(a,b) as c" syntax looks a bit weird to me
2) I would define DataTextField and DataValueField.
3) Have you checked that you have actually returned rows ?
4 ) My approach would be to bind with a table created from scratch to find
out first if the problem is UI side or data side. If you still see nothign
but have data, it could be that you rebind in some other event (in which
event do you have this ?).

Good luck.

--
Patrice

Antonio said:
This is what I tried:

//binding for the State drop-down
string strTable = "GEM.states";
string strWhere = "";

if (IsPostBack)
{
strWhere = " WHERE stateid=" + lstState.SelectedItem.Value;
}
string strState = "SELECT *, (statename, stateprefix) as State FROM " +
strTable + strWhere + " ORDER BY stateprefix";

adapter.Fill(ds,strTable);
lstState.DataSource = ds.Tables[strTable].DefaultView;
lstState.DataBind();

Patrice said:
What have you tried that doesn't work ? Defining the DataSource and
calling
DataBind if ASP.NET should be enough.

You may want also to post in a windows forms or an ASP.NET group so that
we
know which kind of UI you are using...

--
Patrice

"Antonio" <[email protected]> a écrit dans le message de
news: (e-mail address removed)...
Can somebody please tell me how to bind a drop-down (states) to a table
programmatically? I have the connection information in the procedure
and
I
am not using the connection objects in the GUI interface.

Thanks,


Antonio
 
Back
Top