473,387 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Mark A selected item on first post. please help

I have tried this with no luck. What i want is to show the selected item on
the first post. the selected item is NY but the first in the list shows as
selected.
If Page.IsPostBack = False Then

Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
Dim myCommand As SqlCommand = New SqlCommand("Get_States",
myConnection)

Dim Statetypes As SqlDataReader

myConnection.Open()

Statetypes = myCommand.ExecuteReader

StateCode.DataSource = Statetypes
StateCode.DataTextField = "State"
StateCode.DataValueField = "StateId"
' Databind and display the list of favorite product items
StateCode.DataBind()
myConnection.Close()

Dim i As Integer
For i = 0 To StateCode.Items.Count - 1
Dim Statechk As String = StateCode.Items(i).Value
Dim chk = StateCode.DataValueField
If Statechk = customerDetails.State Then
StateCode.SelectedItem.Selected = True
End If
Next
end if

Jul 21 '05 #1
3 1744
Hi,

Your problem is in this code:
For i = 0 To StateCode.Items.Count - 1
Dim Statechk As String = StateCode.Items(i).Value
Dim chk = StateCode.DataValueField
If Statechk = customerDetails.State Then
StateCode.SelectedItem.Selected = True
End If
Next
The line below doesn't do anything new. It is constantly setting the
selected item to be selected again.

StateCode.SelectedItem.Selected = True

You would want to do something like this in its place:

StateCode.Items(i).Selected = True

Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:CB**********************************@microsof t.com... I have tried this with no luck. What i want is to show the selected item on the first post. the selected item is NY but the first in the list shows as
selected.
If Page.IsPostBack = False Then

Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
Dim myCommand As SqlCommand = New SqlCommand("Get_States",
myConnection)

Dim Statetypes As SqlDataReader

myConnection.Open()

Statetypes = myCommand.ExecuteReader

StateCode.DataSource = Statetypes
StateCode.DataTextField = "State"
StateCode.DataValueField = "StateId"
' Databind and display the list of favorite product items
StateCode.DataBind()
myConnection.Close()

Dim i As Integer
For i = 0 To StateCode.Items.Count - 1
Dim Statechk As String = StateCode.Items(i).Value
Dim chk = StateCode.DataValueField
If Statechk = customerDetails.State Then
StateCode.SelectedItem.Selected = True
End If
Next
end if

Jul 21 '05 #2
Hi,

I forgot to mention after you set the Selected property to True then put in
an Exit For to exit you from the loop:

If Statechk = customerDetails.State Then
StateCode.Items(i).Selected = True
Exit For 'Get out before it finds another one! Just kidding....
End If

Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:ej**************@TK2MSFTNGP09.phx.gbl...
Hi,

Your problem is in this code:
For i = 0 To StateCode.Items.Count - 1
Dim Statechk As String = StateCode.Items(i).Value
Dim chk = StateCode.DataValueField
If Statechk = customerDetails.State Then
StateCode.SelectedItem.Selected = True
End If
Next


The line below doesn't do anything new. It is constantly setting the
selected item to be selected again.

StateCode.SelectedItem.Selected = True

You would want to do something like this in its place:

StateCode.Items(i).Selected = True

Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:CB**********************************@microsof t.com...
I have tried this with no luck. What i want is to show the selected item

on
the first post. the selected item is NY but the first in the list shows as selected.
If Page.IsPostBack = False Then

Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
Dim myCommand As SqlCommand = New SqlCommand("Get_States",
myConnection)

Dim Statetypes As SqlDataReader

myConnection.Open()

Statetypes = myCommand.ExecuteReader

StateCode.DataSource = Statetypes
StateCode.DataTextField = "State"
StateCode.DataValueField = "StateId"
' Databind and display the list of favorite product items
StateCode.DataBind()
myConnection.Close()

Dim i As Integer
For i = 0 To StateCode.Items.Count - 1
Dim Statechk As String = StateCode.Items(i).Value
Dim chk = StateCode.DataValueField
If Statechk = customerDetails.State Then
StateCode.SelectedItem.Selected = True
End If
Next
end if


Jul 21 '05 #3
It works !!!
thank You
Stan

"Stanley J Mroczek" wrote:
I have tried this with no luck. What i want is to show the selected item on
the first post. the selected item is NY but the first in the list shows as
selected.
If Page.IsPostBack = False Then

Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
Dim myCommand As SqlCommand = New SqlCommand("Get_States",
myConnection)

Dim Statetypes As SqlDataReader

myConnection.Open()

Statetypes = myCommand.ExecuteReader

StateCode.DataSource = Statetypes
StateCode.DataTextField = "State"
StateCode.DataValueField = "StateId"
' Databind and display the list of favorite product items
StateCode.DataBind()
myConnection.Close()

Dim i As Integer
For i = 0 To StateCode.Items.Count - 1
Dim Statechk As String = StateCode.Items(i).Value
Dim chk = StateCode.DataValueField
If Statechk = customerDetails.State Then
StateCode.SelectedItem.Selected = True
End If
Next
end if

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Peter Moscatt | last post by:
I am having trouble understanding the methods for the Listbox from Tk. If I was to select at item in the list using a mouse click (have already created the bind event) - what method returns the...
0
by: Stanley J Mroczek | last post by:
How do I mark the item that selected in the dropdownlist . the state is is ny and i want to mark was selected on the first page. If Page.IsPostBack = False Then Dim statefile As CustomersDB...
10
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
3
by: Stanley J Mroczek | last post by:
I have tried this with no luck. What i want is to show the selected item on the first post. the selected item is NY but the first in the list shows as selected. If Page.IsPostBack = False Then...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
3
by: Iain | last post by:
Hi All I have 2 DropDownList boxes on a page. The first (id= "Operation") is populated on PageLoad with the contents of a database table. The second id="WorkStations" will not be populated...
4
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the...
6
by: probashi | last post by:
Hi, Issue: After post back selected item of a list box is getting out of focus (when it contains more items than it's size). I have a List Box in an ASPX page. I select an item from the...
1
by: cluce | last post by:
I have some prices listed in a checkboxlist that I am trying to add up. First I was going to add the mto a list box and add them up that way but I forgot how to do it. Its been awhile and I dont have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.