Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop Down Data binding 2

Status
Not open for further replies.

kermitforney

Technical User
Mar 15, 2005
374
US
Have some strange behavior mucking up my combobox. For some reason when the data is pulled it is displayed vertically.

So, the recruiters name looks like this:

T
o
m

S
a
w
y
e
r

Not sure why this is happening, any help is greatly appreciated.

FYI ~ .Net noob here, so I am at a white belt status. :eek:)

Code:
 cmdRecruiters.CommandText = "stpRecruiters2"
                dtr = cmdRecruiters.ExecuteReader()
                dtr.Read()


                dtb.Clear()
                dtb.Columns.Add(New DataColumn("strAssignedRecruiter", GetType(String)))
                drw = dtb.NewRow
                drw("strAssignedRecruiter") = dtr("strAssignedRecruiter")
                dtb.Rows.Add(drw)


                cboRecruiter.DataSource = dtr("strAssignedRecruiter")
                cboRecruiter.DataBind()

                dtr.Close()
 
I don't know why you are doing the read and all the code inbetween binding the dropdownlist.

Try simply doing this and see if it works:
Code:
cboRecruiter.DataSource = dtr
cboRecruiter.DataTextField="DataSourceField"
cboRecruiter.DataValueField="DataValueField"
cboRecruiter.DataBind()
 
Worked like a charm j, thanks again. I only have one remaining problem left.

When the combobox is displayed at run time, the first row that is supposed to be returned is not. So I am missing the first row returned by the stored procedure.
 
Did you verify that the stored procedure is returning what you want?
I have to say, I don't use datareaders, so maybe there is a step that I am missing in my example code. Perhaps you can find something more online.

I usually get a datatable and bind that, or you can use ExecuteDataset and set the datasource to the dataset.tables(0) with the same datavalue and datatext fields.
 
I am still new to this as well.

jbenson001
I don't use datareaders

Why not? What is the downfall?

Just curious.

Thanks,
Chilly442
---------------------------------------
If I lived anywhere else I'd be Sunny442
 
Oh, there is no downfall, in fact, there are many reasons to use datareaders. It's just that we have a DAL here that is based off of Microsoft's Data Access Block. In that we can easily return datasets, or datatables etc. I just find it easier to return a datatable and bind.

Don't get me wrong, I have nothing against datareaders.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top