Problems wit Databinding to a DropDown box

K

Kris Rockwell

Hello,

I have done the following to bind data to a DropDown box:

1. Drag SQLServer table onto web form to create data connection and data
adapter.

2. Generate dataset by right-clicking on the data adapter ad selecting
generate dataset.

3. Setting the drop down box propertied to reflect so that:

Datasource = Dataset11
Datamember = table
Datatextfield = tablerow
Datavaluefield = tablerow

When I run the application I don't generate any errors, but no data is
present in the DropDown box...Well, actually I get a drop down that is
blank.

Any ideas an what Imay be doing wrong?

Also, if I code the information, can I put it in the CodeBehind file or does
it have to be in the actual ASPX?

Thanks in advance,
Kris
 
K

Kris Rockwell

I haven't explicitly called it in the code, but I have set it in the
Property page of the DropDown Box.

I did try it though and still got no results. It is strange, though...The
box seems populated in that I can drop it down, but there is no content as
there should be.

Kris
 
S

Scott M.

You can't call the DataBind method (or any method of any object for that
matter) via the design-time property box. It must be called from code. The
fact that the box drops down with noting in it is what all drop down boxes
that don't have data in them do.

Let's see your entire Page_Load event handler.


Kris Rockwell said:
I haven't explicitly called it in the code, but I have set it in the
Property page of the DropDown Box.

I did try it though and still got no results. It is strange, though...The
box seems populated in that I can drop it down, but there is no content as
there should be.

Kris
 
K

Kris Rockwell

Here is the code:

Sub Page_Load
cbACType.DataBind()
End Sub

The database connection information is in my CodeBehind vb file.

Regards,
Kris
Scott M. said:
You can't call the DataBind method (or any method of any object for that
matter) via the design-time property box. It must be called from code. The
fact that the box drops down with noting in it is what all drop down boxes
that don't have data in them do.

Let's see your entire Page_Load event handler.


message news:[email protected]...
 
S

Scott M.

Can we have the db connection code as well?

By the way, only call the DataBind method on the first page call (ViewState
will take care of keeping the dropdown list populated after that. So, your
page_load code should be:

Sub Page_Load
If Not IsPostBack Then
cbACType.DataBind()
End If
End Sub


Kris Rockwell said:
Here is the code:

Sub Page_Load
cbACType.DataBind()
End Sub

The database connection information is in my CodeBehind vb file.

Regards,
Kris
 
K

Kris Rockwell

Well, I have kep the DB connection in the code behind page in an effort to
keep it seperate (and thus away from the eyes of curious users) from the
ASPX. In testing different methods I have deleted from the VB code at the
moment,so I will have to write it back in before I post the code. Couldn't I
use the Connection and DataAdapter objects within .NET for this?

Kris


Scott M. said:
Can we have the db connection code as well?

By the way, only call the DataBind method on the first page call (ViewState
will take care of keeping the dropdown list populated after that. So, your
page_load code should be:

Sub Page_Load
If Not IsPostBack Then
cbACType.DataBind()
End If
End Sub


message news:[email protected]...
 
S

Scott M.

Kris,

All of your compiled code goes in the code-behind. That is what it is there
for. Even if you use the Visual DataAdapter and Connection controls, you
are still working with code in the code-behind. When you use those
controls, code is written for you in the code-behind, instead of you
declaring and configuring the classes yourself.

Regardless of whether or not you use the controls or write the code
yourself, we need to see your code in order to help you solve your problem.

Since all it really takes to get the DropDownList control working is to set
its DataSource and DataField properties and then to call its DataBind method
on the first page call (and you seem to have done that), we can assume that:

either your database connection is not setup correctly or
you are connecting to the db, but not retuning any data

We won't know until you provide us with everything you have.


Kris Rockwell said:
Well, I have kep the DB connection in the code behind page in an effort to
keep it seperate (and thus away from the eyes of curious users) from the
ASPX. In testing different methods I have deleted from the VB code at the
moment,so I will have to write it back in before I post the code. Couldn't I
use the Connection and DataAdapter objects within .NET for this?

Kris
 
K

Kris Rockwell

OK...I got it.

I created a SQLConnection, DataAdapter and Dataset. In the Page load I had
to call the DataBin() and fill the dataset. That was the problem, the
Dataset wasn't being filled.

Thanks for all of your help.

Regards,
Kris
Scott M. said:
Kris,

All of your compiled code goes in the code-behind. That is what it is there
for. Even if you use the Visual DataAdapter and Connection controls, you
are still working with code in the code-behind. When you use those
controls, code is written for you in the code-behind, instead of you
declaring and configuring the classes yourself.

Regardless of whether or not you use the controls or write the code
yourself, we need to see your code in order to help you solve your problem.

Since all it really takes to get the DropDownList control working is to set
its DataSource and DataField properties and then to call its DataBind method
either your database connection is not setup correctly or
you are connecting to the db, but not retuning any data

We won't know until you provide us with everything you have.


message news:[email protected]...
Well, I have kep the DB connection in the code behind page in an effort to
keep it seperate (and thus away from the eyes of curious users) from the
ASPX. In testing different methods I have deleted from the VB code at the
moment,so I will have to write it back in before I post the code.
Couldn't
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top