Microsoft
Software
Hardware
Network
Question : Referring to Data in a Drop Down List that is selected
I ahve the following code where I am opening an SQL Connection and executing a Sql Query to load and populate a Drop Down List Box which I have defined as DDLIssue.
My coding:
PopulateIssue()
End Sub
Sub PopulateIssue()
'Create the connection
'Dim strConnectionString As String = ConfigurationManager.Conne
ctionStrin
gs("SqlCon
nectionStr
ing").Conn
ectionStri
ng
Dim myConnection = New SqlConnection(clsDAL.CallI
ssueConnec
tion())
'Query to execute
Dim strQuery As String = "Select IssueID, Issue FROM Issue ORDER BY Issue"
'Create the Command
Dim myCommand As New SqlCommand(strQuery, myConnection)
'The Try Catch Statement determines whether there is a Database Connection
'An error message appears informing the user.
Try
'Open the database connection
myConnection.Open()
Catch ex As Exception
QueryResult.Text = "Database Connection Failed!"
Exit Sub
End Try
'Run the Query
Dim myReader As SqlDataReader = myCommand.ExecuteReader()
'Set the datasource and bind the fields
DDLIssue.DataSource = myReader
DDLIssue.DataTextField = "Issue"
DDLIssue.DataValueField = "Issue"
DDLIssue.DataBind()
'Close the Reader
myReader.Close()
'Always close the connection when you are finished
myConnection.Close()
End Sub
Protected Sub DDLIssue_DataBound(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DDLIssue.DataBound
Dim myListItem As New ListItem()
myListItem.Text = "Please select..."
myListItem.Value = "0"
DDLIssue.Items.Insert(0, myListItem)
End Sub
My Drop Down List populates with the coding above when I run my application.
I am trying to use this Drop Down List box to load a textbox which I have defined as txtIssue.Text.
I want the user to select an Item from the DDLIssue Drop Down Box and insert the data to the txtIssue textbox when I have the use select an UPDATE button which I have deined in VB code.
The Problem I am having is when I select an Item from the DDLIssue Drop Down it is inserting in the txtIssue textbox as "0". I need to be able to select an item from the DDLIssue drop down list and have that item appear in the txtIssue Textbox. I do not want the Index to show which.
I am using the wroing name somehow when I a referencing the DDLIssue drop down list box. I tried referencing it as DDLIssue.Selectedvalue.tex
t, but I am still seeing "0" here when I debug and hover the mouse over the field with a breakpoint I have set.
Any help is appreciated. I just do not know how to reference what is in the field when it is coming in. I want the suer to select an item from the DDLIssue and have that item appear in the txtIssue textbox, not "0"
jjc9809
Answer : Referring to Data in a Drop Down List that is selected
When you are creating the drop down you are not setting the value member for the id or the text member which will return the correct text string for you.
Posted via EE Mobile
Random Solutions
GroupWise 6.0.1 - Some addresses are undeliverable and have been crossed out
I'm trying to config route and vpn in Ubuntu
Installing Small Business Server 2008 trail
css easy question - page items apprearing low down
How to connect treeview & listview or grid through Access database
In Outlook, Advanced Find - Search for Attachment name
How to configure Active Sync in Exchange 2003 and iPhone 3GS
ghost 14 in windows xp is requiring me to run in windows recovery enviroment
How do I hide site tabs from certain users?
Redistributing RIP into OSPF non-contiguous subnets.