473,834 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stupid Dumba**ed question about ASP.NET...

I am trying to write code that will go through the existing list items in a
listbox and perform a string comparision with a supplied string. That
particular item will automatically selected if there is a match. I am
trying to use the IndexOf method to accomplish this task but, alas, I have
been unsuccessful.

If anyone has any ideas or suggestions it would be much appreciated.

Yes, I am a newbie to ASP.NET.
Yes, I am a newbie to VB.NET.

I am familiar with ASP.Classic and maybe that's my problem.
Here's my code:
=====
Protected lstIncdType as ListBox
...
Dim j as Integer
Dim Thingy as ListItem
...
j = 0

For Each Thingy In lstIncdType.Ite ms
If Thingy.Text = CompareString Then
j = IndexOf(What!?! ) 'Offending Code...
Exit For
End If

Next

lstIncdType.Sel ectedIndex = j
...
=====

TIA
Nov 18 '05 #1
3 1498
maybe something like:

Protected lstIncdType as ListBox
...
Dim j as Integer
Dim Thingy as ListItem
...

For j=0 to lstIncdType.Ite ms.Count-1
Thingy = CType( lstIncdType.Ite ms(j), ListItem)
If Thingy.Text = CompareString Then
lstIncdType.Sel ectedIndex = j
Exit For
End If
Next

Eeediot wrote:
I am trying to write code that will go through the existing list items in a
listbox and perform a string comparision with a supplied string. That
particular item will automatically selected if there is a match. I am
trying to use the IndexOf method to accomplish this task but, alas, I have
been unsuccessful.

If anyone has any ideas or suggestions it would be much appreciated.

Yes, I am a newbie to ASP.NET.
Yes, I am a newbie to VB.NET.

I am familiar with ASP.Classic and maybe that's my problem.
Here's my code:
=====
Protected lstIncdType as ListBox
...
Dim j as Integer
Dim Thingy as ListItem
...
j = 0

For Each Thingy In lstIncdType.Ite ms
If Thingy.Text = CompareString Then
j = IndexOf(What!?! ) 'Offending Code...
Exit For
End If

Next

lstIncdType.Sel ectedIndex = j
...
=====

TIA

--
mikeb
Nov 18 '05 #2
No need to feel bad about not knowing something. Nobody knows it all and we
all started as newbies.

Anyway, it seems like you're doing this the hard way. You can get the index
quite quickly like this:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles MyBase.Load
Dim j As Integer
j = lstIncdType.Ite ms.IndexOf _
(lstIncdType.It ems.FindByText( "Blue"))
Label1.Text = "Blue is item " & _
j.ToString & " (zero-based)"
CheckForText()
End Sub

If you need to check for a partial string, you can get it like this:
Sub CheckForText()
Dim j As Integer
Dim Thingy As ListItem
For Each Thingy In lstIncdType.Ite ms
If InStr(Thingy.Te xt, "Blu") Then
j = lstIncdType.Ite ms.IndexOf(Thin gy)
Exit For
End If
Next
Label1.Text = "Search for 'Blu'... see zero-based item " & _
j.ToString
End Sub
<form id="Form1" method="post" runat="server">
<P>
<asp:ListBox id="lstIncdType " runat="server">
<asp:ListItem Value="Red">Red </asp:ListItem>
<asp:ListItem Value="Green">G reen</asp:ListItem>
<asp:ListItem Value="Blue">Bl ue</asp:ListItem>
<asp:ListItem Value="Black">B lack</asp:ListItem>
<asp:ListItem Value="Yellow"> Yellow</asp:ListItem>
</asp:ListBox></P>
<P>
<asp:Label id="Label1" runat="server"> Label</asp:Label></P>
</form>
You need to put in some error checking because the preceding will give false
results for the zero item.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
"Eeediot" <ee*****@hotmai l.com> wrote in message
news:6s******** ************@gi ganews.com...
I am trying to write code that will go through the existing list items in a
listbox and perform a string comparision with a supplied string. That
particular item will automatically selected if there is a match. I am
trying to use the IndexOf method to accomplish this task but, alas, I have
been unsuccessful.

If anyone has any ideas or suggestions it would be much appreciated.

Yes, I am a newbie to ASP.NET.
Yes, I am a newbie to VB.NET.

I am familiar with ASP.Classic and maybe that's my problem.
Here's my code:
=====
Protected lstIncdType as ListBox
...
Dim j as Integer
Dim Thingy as ListItem
...
j = 0

For Each Thingy In lstIncdType.Ite ms
If Thingy.Text = CompareString Then
j = IndexOf(What!?! ) 'Offending Code...
Exit For
End If

Next

lstIncdType.Sel ectedIndex = j
...
=====

TIA


Nov 18 '05 #3
Use a loop with a counter:

Dim i As Integer
For i = 0 To lstIncdType.Ite ms.Count - 1
If lstIncdType.Ite ms(i).Text = CompareString Then
lstIncdType.Sel ectedIndex = i
Exit For
End If
Next

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Eeediot" <ee*****@hotmai l.com> wrote in message
news:6s******** ************@gi ganews.com...
I am trying to write code that will go through the existing list items in a listbox and perform a string comparision with a supplied string. That
particular item will automatically selected if there is a match. I am
trying to use the IndexOf method to accomplish this task but, alas, I have
been unsuccessful.

If anyone has any ideas or suggestions it would be much appreciated.

Yes, I am a newbie to ASP.NET.
Yes, I am a newbie to VB.NET.

I am familiar with ASP.Classic and maybe that's my problem.
Here's my code:
=====
Protected lstIncdType as ListBox
...
Dim j as Integer
Dim Thingy as ListItem
...
j = 0

For Each Thingy In lstIncdType.Ite ms
If Thingy.Text = CompareString Then
j = IndexOf(What!?! ) 'Offending Code...
Exit For
End If

Next

lstIncdType.Sel ectedIndex = j
...
=====

TIA

Nov 18 '05 #4

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

Similar topics

77
5699
by: nospam | last post by:
Reasons for a 3-tier achitecture for the WEB? (NOTE: I said, WEB, NOT WINDOWS. DON'T shoot your mouth off if you don't understand the difference.) I hear only one reason and that's to switch a database from SQL Server to Oracle or DB2 or vice versa... and that's it.... And a lot of these enterprises don't need it as they already know what database they are going to use and they don't plan on switching in and out database in the first...
125
14885
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
7
1324
by: PullnOutHair | last post by:
I know that I should know how to do this, but for some reason it is escapeing me right now and I was hoping someone here could help. I need to setup a pointer to the memory location 0x30000000. I am working on a linux system that has hardware inputs remapped to that address and I have to read them. I am just drawing a blank on how to actually assign the address of a pointer to point to.
28
3287
by: Madhur | last post by:
Hello what about this nice way to open a file in single line rather than using if and else. #include<stdio.h> void main() { FILE *nd; clrscr(); fopen("c:\\autoexec.bat","r")&&printf("success") || printf("error opeing
2
2309
by: Lampa Dario | last post by:
Hi, where is this stupid error in this program? When I execute it, i receive a segmentation fault error. #include <stdio.h> int main(int argc, char *argv, char *env) { int i=0; int l=0; int word=0; char *querystring; querystring=malloc(sizeof(char)*100000); if (getenv("QUERY_STRING")==NULL)
10
3445
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a database or continue to process on to the next page. I am now trying to learn ASP to see if we can replace some of our applications that were written in php with an ASP alternative. However, after doing many searches on google and reading a couple...
6
11680
by: Alejandro Dubrovsky | last post by:
I see from googling around that this is a popular topic, but I haven't seen anyone saying "ah, yes, that works", so here it goes. How does one connect through a proxy which requires basic authorisation? The following code, stolen from somewhere, fails with a 407: proxy_handler = urllib2.ProxyHandler({"http" : "http://the.proxy.address:3128"}) proxy_auth_handler = urllib2.ProxyBasicAuthHandler() proxy_auth_handler.add_password("The...
5
1530
by: sherifffruitfly | last post by:
Hi all, I'm certain this is stupid, but I'd like to know how to keep a form open for, say, longer than 1ms. Here's the code I'm using to open my form: TestModelFileReaderForm modelInfo = new TestModelFileReaderForm(); modelInfo.txtModelInfo.Text = elementInfo; modelInfo.Show();
28
1741
by: Joe Reynolds | last post by:
this is kinda off topic, but not totally. i have an ASP page that pulls text from a database, stores it in a variable, then uses <%= variable %to write the text inside an html table. the problem im having has to do with wrapping. if the line of text is longer than the table (or column) is wide, then the whole table is blown apart and grows to fit the data. i was hoping for an easy way to fix this with CSS but the only thing i can find...
0
9646
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
10510
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
10548
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
10219
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
9331
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
7758
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
6954
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();...
1
4427
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
3978
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.