Real Problem

B

Big E

Okay here is my code. I'm using ASP.Net and SQL Server 2000. When I run this
code the selecteditem.value is 1 the selecteditem.text is ALABAMA. This is
correct. But when I try and get the value once this procedure has run my
selecteditem.value is ALABAMA and the selecteditem.text is ALABAMA. It's not
keeping the selecteditem.value after I change the combobox selection.

Thanks.

Big E

Dim Portal As String
Dim dsState As DataSet
Dim cnPortal As SqlConnection
Dim daState As SqlDataAdapter
Dim dtState As DataTable = New DataTable
Portal = ConfigurationSettings.AppSettings("Portal.ConnectionString")
dsState = New DataSet
cnPortal = New SqlConnection(Portal)
daState = New SqlDataAdapter("SELECT * FROM tlkpState", cnPortal)
daState.Fill(dsState, "tlkpState")
dtState = dsState.Tables("tlkpState")
Dim i As Integer


For i = 0 To dtState.Rows.Count - 1


cboStateCompany.Items.Add(dtState.Rows(i)("StateCode"))

cboStateCompany.SelectedItem.Value = (dtState.Rows(i)("StateId"))

cboStateCompany.SelectedItem.Text = (dtState.Rows(i)("StateCode"))

Next

cnPortal.Close()
cnPortal = Nothing
 
C

Curt_C [MVP]

check your binding, it looks like you are rebinding with JUST the state
passed to the DDL, not the ID & State.
 
C

Cliff Harris

I'm not positive why that's not working, however, you might want to consider
looking into binding your datatable to the combobox instead of adding each
item individually, it's easier, and avoids user error:

Dim Portal As String
Dim dsState As DataSet
Dim cnPortal As SqlConnection
Dim daState As SqlDataAdapter
Dim dtState As DataTable = New DataTable
Portal = ConfigurationSettings.AppSettings("Portal.ConnectionString")
dsState = New DataSet
cnPortal = New SqlConnection(Portal)
daState = New SqlDataAdapter("SELECT * FROM tlkpState", cnPortal)
daState.Fill(dsState, "tlkpState")
dtState = dsState.Tables("tlkpState")

cboStateCompany.DataSource = dtState
cboState.DataValueField= "StateId"
cboState.DataTextField = "StateCode"
cboStateCompany.DataBind()

cnPortal.Close()
scnPortal = Nothing

see if that fixes anything for you...
(also, if my syntax is incorrect, sorry, I'm a C# programmer... VB.Net is
not my forte)

HTH,
-Cliff
 
B

Big E

Thanks Cliff it works now.


Cliff Harris said:
I'm not positive why that's not working, however, you might want to consider
looking into binding your datatable to the combobox instead of adding each
item individually, it's easier, and avoids user error:

Dim Portal As String
Dim dsState As DataSet
Dim cnPortal As SqlConnection
Dim daState As SqlDataAdapter
Dim dtState As DataTable = New DataTable
Portal = ConfigurationSettings.AppSettings("Portal.ConnectionString")
dsState = New DataSet
cnPortal = New SqlConnection(Portal)
daState = New SqlDataAdapter("SELECT * FROM tlkpState", cnPortal)
daState.Fill(dsState, "tlkpState")
dtState = dsState.Tables("tlkpState")

cboStateCompany.DataSource = dtState
cboState.DataValueField= "StateId"
cboState.DataTextField = "StateCode"
cboStateCompany.DataBind()

cnPortal.Close()
scnPortal = Nothing

see if that fixes anything for you...
(also, if my syntax is incorrect, sorry, I'm a C# programmer... VB.Net is
not my forte)

HTH,
-Cliff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top