Hi,
I am using
VB.NET and codebehind to try to place a dropdownlist value in a database. Seems pretty simple and I have everything displaying OK but I can't seem to pull the value. It seems to return the name of the field in the datasource(projecttypeid) rather than the actual value (ie:14)
Here is my code:
dropdownlist creation:
'Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("D BConnection"))
'Global Variables (Database connection,Adapter, and SQL String)
Dim SQLConnection AS SQLConnection
Dim SQLDataAdapter AS SQLDataAdapter
Dim SQLCommand AS SQLCommand
'Dropdown List Variables (Recordset)
Dim ProjectTypeDS AS DataSet
' Open your database connection (only done once)
SQLConnection = New SqlConnection(ConfigurationSettings.AppSettings("D BConnection"))
' Set your query string
SQLCommand = New SQLCommand("Select * from B_Project_Type",SQLConnection)
'Initiate the Adapter and the Dataset
SQLDataAdapter = New SQLDataAdapter(sqlCommand)
ProjectTypeDS = New DataSet()
'Populate the DataSet
SQLDataAdapter.Fill(ProjectTypeDS,"ProjectType")
'Apply Sort
ProjectTypeDS.Tables(0).DefaultView.Sort = "Project Type"
ProjectTypeID.DataSource= ProjectTypeDS.Tables("ProjectType")'.DefualtView
ProjectTypeID.DataTextField = "Project Type"
ProjectTypeID.DataValueField = "ProjectTypeID"
ProjectTypeID.DataBind()
ProjectTypeID.Items.Insert(0,New ListItem())
There is a button called new. When I click it I want the value returned. This is my onclick code....
Private Sub BtnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNew.Click
ProjectID.Text = ProjectTypeID.DataValueField
End Sub
My source code for the dropdown looks like this:
<TD style="WIDTH: 186px">Bucket</TD>
<TD><select name="ProjectTypeID" id="ProjectTypeID">
<option value=""></option>
<option value="8">Cancelled</option>
<option value="4">Completed</option>
<option value="5">On Hold</option>
<option value="6">Prioritized</option>
<option value="7">Quick & Dirty</option>
<option value="10">Scheduled</option>
<option value="9">Time Sensitive</option>
<option value="2">To Be Prioritized</option>
<option value="11">To Be Scheduled</option>
<option value="3">Upcoming</option>
<option value="1">Work In Process</option>
</select></TD>
For some reason... if I pick Work In Process and click new. The text populates as "ProjectTypeID" rather than 1.
Any ideas?
Thanks in advance.