I posted a message about this a few weeks ago, and my question is how
to show values from Multiple DB Columns in a DropDownList (VB.NET 03
and Access 2k). The format works, however it repeats the same first
value for the entire contents. How can I fix this? Thanks!
My code is as follows:
Dim strTID As String
Dim cmdT As OleDbCommand
Dim dtrT As OleDbDataReader
Dim dbCampus
Dim tsFix As String
'GET STUDENT INFO
strTID = "Select * From GlobalUsersWeb"
cmdT = New OleDbCommand(strTID, conPI)
conPI.Open()
dtrT = cmdT.ExecuteReader()
While dtrT.Read()
Dim sln
Dim dfn
Dim sid
sln = dtrT.Item("SLName")
dfn = dtrT.Item("SFName")
sid = dtrT.Item("UserID")
tsFix = String.Format("{0}, {1} ({2})", sln, dfn, sid)
dropGS.DataSource = dtrT
dropGS.DataTextField = "UserID"
dropGS.DataTextFormatString = tsFix
dropGS.DataValueField = "UserID"
dropGS.DataBind()
End While
dtrT.Close()
conPI.Close()
Within a sub run at Page_Load
The ouput HTML is the following:
<select name="dropGU" id="dropGU" class="cmdButton">
<option value="1003">Doe, John (1002)</option>
<option value="1004">Doe, John (1002)</option>
<option value="1005">Doe, John (1002)</option>
<option value="1006">Doe, John (1002)</option>
<option value="1007">Doe, John (1002)</option>
<option value="1008">Doe, John (1002)</option>
<option value="1009">Doe, John (1002)</option>
<option value="1010">Doe, John (1002)</option>
<option value="1011">Doe, John (1002)</option>
<option value="1012">Doe, John (1002)</option>
<option value="1013">Doe, John (1002)</option>
<option value="1014">Doe, John (1002)</option>
<option value="1015">Doe, John (1002)</option>
<option value="1016">Doe, John (1002)</option>
<option value="1017">Doe, John (1002)</option>
<option value="1018">Doe, John (1002)</option>
<option value="1019">Doe, John (1002)</option>
<option value="1020">Doe, John (1002)</option>
<option value="1021">Doe, John (1002)</option>
<option value="1022">Doe, John (1002)</option>
<option value="1023">Doe, John (1002)</option>
<option value="1024">Doe, John (1002)</option>
<option value="1025">Doe, John (1002)</option>
<option value="3001">Doe, John (1002)</option>
<option value="3002">Doe, John (1002)</option>
<option value="3003">Doe, John (1002)</option>
<option value="3004">Doe, John (1002)</option>
</select> 1 1403
Schultz, you're telling it to use a format string that is a literal (there's
no {0} left because you've already replaced it, so the UserId on each row has
nowhere to go), and each row is going to keep using that same string.
A few ways to go, but probably easiest: create a formatted column in your
datareader (either on the query or manually), e.g. FullName, with your Id,
First, and Last in a string the way you want it. Then use that name in your
DataTextField and skip the DataTextFormatString.
Not quite as easy (but I think way cleaner and more flexible): on
ItemDataBound of the dropdown get the values from your data source and format
and stuff them in directly.
Bill
"Schultz" wrote: I posted a message about this a few weeks ago, and my question is how to show values from Multiple DB Columns in a DropDownList (VB.NET 03 and Access 2k). The format works, however it repeats the same first value for the entire contents. How can I fix this? Thanks!
My code is as follows:
Dim strTID As String Dim cmdT As OleDbCommand Dim dtrT As OleDbDataReader Dim dbCampus Dim tsFix As String
'GET STUDENT INFO strTID = "Select * From GlobalUsersWeb" cmdT = New OleDbCommand(strTID, conPI) conPI.Open() dtrT = cmdT.ExecuteReader() While dtrT.Read()
Dim sln Dim dfn Dim sid
sln = dtrT.Item("SLName") dfn = dtrT.Item("SFName") sid = dtrT.Item("UserID")
tsFix = String.Format("{0}, {1} ({2})", sln, dfn, sid) dropGS.DataSource = dtrT dropGS.DataTextField = "UserID" dropGS.DataTextFormatString = tsFix
dropGS.DataValueField = "UserID" dropGS.DataBind()
End While dtrT.Close() conPI.Close()
Within a sub run at Page_Load
The ouput HTML is the following:
<select name="dropGU" id="dropGU" class="cmdButton"> <option value="1003">Doe, John (1002)</option> <option value="1004">Doe, John (1002)</option> <option value="1005">Doe, John (1002)</option> <option value="1006">Doe, John (1002)</option> <option value="1007">Doe, John (1002)</option> <option value="1008">Doe, John (1002)</option> <option value="1009">Doe, John (1002)</option> <option value="1010">Doe, John (1002)</option> <option value="1011">Doe, John (1002)</option> <option value="1012">Doe, John (1002)</option> <option value="1013">Doe, John (1002)</option> <option value="1014">Doe, John (1002)</option> <option value="1015">Doe, John (1002)</option> <option value="1016">Doe, John (1002)</option> <option value="1017">Doe, John (1002)</option> <option value="1018">Doe, John (1002)</option> <option value="1019">Doe, John (1002)</option> <option value="1020">Doe, John (1002)</option> <option value="1021">Doe, John (1002)</option> <option value="1022">Doe, John (1002)</option> <option value="1023">Doe, John (1002)</option> <option value="1024">Doe, John (1002)</option> <option value="1025">Doe, John (1002)</option> <option value="3001">Doe, John (1002)</option> <option value="3002">Doe, John (1002)</option> <option value="3003">Doe, John (1002)</option> <option value="3004">Doe, John (1002)</option>
</select>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave Pylatuk |
last post by:
Hello all. I have a question about updating a LONG datatype
column in Oracle 8.1.7.
I have a STUDENT table like:
student_id INTEGER PK
student_comments LONG
I want to...
|
by: Nick Heppleston |
last post by:
I have a concatenation problem and I was wondering if somebody might be
able to offer some help :-)
I have the following table structure holding product long descriptions:
Part...
|
by: Dennis |
last post by:
In CSS3 it looks like we'll have multiple column flowing of text
(newspaper style) in which the number of columns can be determined
automatically given the available horizontal space....
|
by: Danny Lesandrini |
last post by:
I'm using an Access database to drive a web site and the
colors of various table backgrounds are stored in Access.
I want users of the Access database to be able to select
colors for the site, but...
|
by: DotNetJunky |
last post by:
I have built a control that runs an on-line help system. Depending on the
category you selected via dropdownlist, it goes out and gets the child
subcategories, and if there are any, adds a new...
|
by: HoustonFreeways |
last post by:
I am populating a dropdownlist via a databind to a database. However, the
text to be displayed can be very long, making the dropdownlist very wide. I
need some way to reduce the width of the...
|
by: Tzanko |
last post by:
As we all know, there is a 8060 bytes size limit on SQL Server rows. I
have a table which requires a number of text fields (5 or 6). Each of
these text fields should support a max of 4000...
|
by: MP |
last post by:
Hi
trying to begin to learn database using vb6, ado/adox, mdb format, sql
(not using access...just mdb format via ado)
i need to group the values of multiple fields
- get their possible...
|
by: vstolmech513 |
last post by:
Here goes nothing...
I'm trying to make a report that shows what guys work on what crew, ie. day crew or night crew. For this selection I've got a form with a combo box with either a "D" or "N"...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |