J
Jim in Arizona
When the page loads, a dropdownlist is populated from a table. I
populate the DataTextField with a persons name, and the DataValueField
with the ID of the table (the key field) for further processing.
I also have another field, a bit field, that I need to process on load.
Basically, when the dropdownlist is first populated (when the page is
first visited), and if the first person that shows up in the the
dropdownlist has a bit field in the table marked 1, then I need an image
to load. I can load the image if the user selects a different name from
the dropdownlist that also has a 1 in the bit field, but on on first
load. I tried this:
Dim rdrClient As SqlDataReader
Dim intGroup As Int16
objConnection.Open()
rdrClient = objCommand.ExecuteReader()
ddlClientName.DataSource = rdrClient
ddlClientName.DataTextField = "clientname"
ddlClientName.DataValueField = "id"
ddlClientName.DataBind()
rdrClient.Close()
intGroup = objCmdGroup.ExecuteScalar()
objConnection.Close()
If intGroup = 0 Then
imgGroup.Visible = False
Else
imgGroup.Visible = True
End If
I placed in some response.write's to see what the sql string looked like
and I saw that no ID was being placed into the SQL string. I'm guessing
that all the code is being processed before any control is actually
rendered and populated with data (the dropdownlist).
So, how can I get the value of a column from the first item in a
dropdownlist on page load without changing the values of the
DataTextField or DataValueField to the data column that I need? Too bad
there wasn't another 'hidden' field in a dropdownlist that I could
populate with more data for conditional programming.
populate the DataTextField with a persons name, and the DataValueField
with the ID of the table (the key field) for further processing.
I also have another field, a bit field, that I need to process on load.
Basically, when the dropdownlist is first populated (when the page is
first visited), and if the first person that shows up in the the
dropdownlist has a bit field in the table marked 1, then I need an image
to load. I can load the image if the user selects a different name from
the dropdownlist that also has a 1 in the bit field, but on on first
load. I tried this:
Dim rdrClient As SqlDataReader
Dim intGroup As Int16
objConnection.Open()
rdrClient = objCommand.ExecuteReader()
ddlClientName.DataSource = rdrClient
ddlClientName.DataTextField = "clientname"
ddlClientName.DataValueField = "id"
ddlClientName.DataBind()
rdrClient.Close()
intGroup = objCmdGroup.ExecuteScalar()
objConnection.Close()
If intGroup = 0 Then
imgGroup.Visible = False
Else
imgGroup.Visible = True
End If
I placed in some response.write's to see what the sql string looked like
and I saw that no ID was being placed into the SQL string. I'm guessing
that all the code is being processed before any control is actually
rendered and populated with data (the dropdownlist).
So, how can I get the value of a column from the first item in a
dropdownlist on page load without changing the values of the
DataTextField or DataValueField to the data column that I need? Too bad
there wasn't another 'hidden' field in a dropdownlist that I could
populate with more data for conditional programming.