473,795 Members | 3,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(C onfigurationSet tings.AppSettin gs("ConnectionS tring"))
Dim myCommand As SqlCommand = New SqlCommand("Get _States",
myConnection)

Dim Statetypes As SqlDataReader

myConnection.Op en()

Statetypes = myCommand.Execu teReader

StateCode.DataS ource = Statetypes
StateCode.DataT extField = "State"
StateCode.DataV alueField = "StateId"
' Databind and display the list of favorite product items
StateCode.DataB ind()
myConnection.Cl ose()

Dim i As Integer
For i = 0 To StateCode.Items .Count - 1
Dim Statechk As String = StateCode.Items (i).Value
Dim chk = StateCode.DataV alueField
If Statechk = customerDetails .State Then
StateCode.Selec tedItem.Selecte d = True
End If
Next
end if

Jul 21 '05 #1
3 1790
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.DataV alueField
If Statechk = customerDetails .State Then
StateCode.Selec tedItem.Selecte d = True
End If
Next
The line below doesn't do anything new. It is constantly setting the
selected item to be selected again.

StateCode.Selec tedItem.Selecte d = 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.m icrosoft.com> wrote in
message news:CB******** *************** ***********@mic rosoft.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(C onfigurationSet tings.AppSettin gs("ConnectionS tring"))
Dim myCommand As SqlCommand = New SqlCommand("Get _States",
myConnection)

Dim Statetypes As SqlDataReader

myConnection.Op en()

Statetypes = myCommand.Execu teReader

StateCode.DataS ource = Statetypes
StateCode.DataT extField = "State"
StateCode.DataV alueField = "StateId"
' Databind and display the list of favorite product items
StateCode.DataB ind()
myConnection.Cl ose()

Dim i As Integer
For i = 0 To StateCode.Items .Count - 1
Dim Statechk As String = StateCode.Items (i).Value
Dim chk = StateCode.DataV alueField
If Statechk = customerDetails .State Then
StateCode.Selec tedItem.Selecte d = 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******** ******@TK2MSFTN GP09.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.DataV alueField
If Statechk = customerDetails .State Then
StateCode.Selec tedItem.Selecte d = True
End If
Next


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

StateCode.Selec tedItem.Selecte d = 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.m icrosoft.com> wrote in
message news:CB******** *************** ***********@mic rosoft.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(C onfigurationSet tings.AppSettin gs("ConnectionS tring"))
Dim myCommand As SqlCommand = New SqlCommand("Get _States",
myConnection)

Dim Statetypes As SqlDataReader

myConnection.Op en()

Statetypes = myCommand.Execu teReader

StateCode.DataS ource = Statetypes
StateCode.DataT extField = "State"
StateCode.DataV alueField = "StateId"
' Databind and display the list of favorite product items
StateCode.DataB ind()
myConnection.Cl ose()

Dim i As Integer
For i = 0 To StateCode.Items .Count - 1
Dim Statechk As String = StateCode.Items (i).Value
Dim chk = StateCode.DataV alueField
If Statechk = customerDetails .State Then
StateCode.Selec tedItem.Selecte d = 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(C onfigurationSet tings.AppSettin gs("ConnectionS tring"))
Dim myCommand As SqlCommand = New SqlCommand("Get _States",
myConnection)

Dim Statetypes As SqlDataReader

myConnection.Op en()

Statetypes = myCommand.Execu teReader

StateCode.DataS ource = Statetypes
StateCode.DataT extField = "State"
StateCode.DataV alueField = "StateId"
' Databind and display the list of favorite product items
StateCode.DataB ind()
myConnection.Cl ose()

Dim i As Integer
For i = 0 To StateCode.Items .Count - 1
Dim Statechk As String = StateCode.Items (i).Value
Dim chk = StateCode.DataV alueField
If Statechk = customerDetails .State Then
StateCode.Selec tedItem.Selecte d = 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
22630
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 text of the selected item ? Pete
0
1180
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 = New CustomersDB type.DataSource = statefile.GetState type.DataBind()
10
10772
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 = true; Where endTime is a string containing "15".
3
243
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 Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) Dim myCommand As SqlCommand = New SqlCommand("Get_States",
11
5815
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
3
5285
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 until the first has been changed The definitions are below.
4
6140
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 extra item just doesn't get added to the DropDownList: ============================================= <script runat="server"> Sub Page_Load(..........) Dim dSet As DataSet Dim sqlConn As SqlConnection
6
16417
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 ListBox and after post back the item is still selected but it is not focused (i.e. I have to scroll down to see the selected item) Any way to fix this!
1
2315
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 my notes with me. Need help please. Or fi somenoe knows any easy way to add up checkbox list values please suggest it. Also, the first loop is only adding the first selected checkbox item not all of them. Protected Sub btnAdd_Click(ByVal...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10439
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.