473,804 Members | 3,229 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 1792
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
1182
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
10773
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
5818
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
3
5286
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
6144
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
16421
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
2316
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
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10588
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...
1
10324
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,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7623
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
6857
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
5527
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...
3
2998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.