473,396 Members | 1,785 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,396 software developers and data experts.

SetIndex and dropdownlist errors

Hi Guys,
I have my .aspx below and i'm using SetIndex with selectedIndex
with DropDownList to retrieve Data from my database!!
My function of SetIndex is as follows:-
Function SetIndex(ByVal TheItem As String)

Dim ItemTypes As ArrayList
Dim i As Integer
For i = 0 To ItemTypes.Count - 1
If TheItem = ItemTypes(i) Then
Return i
End If
Next
End Function

When i compile it using VS.NET it comoiles but when i run it i get error
"Name 'ItemTypes' is not declared"
Do i have to still delcare ItemTypes some how..
Pls help!!

My Asp.Net
------------
<asp:TemplateColumn>
<HeaderTemplate>
Type<br>
<asp:DropDownList id="ItemType" runat="server"
DataSource='<%# ItemTypes %>'/>
</HeaderTemplate>
<ItemTemplate>
<asp:DropDownList id="Dropdownlist1" runat="server"
DataSource='<%# ItemTypes %>'
SelectedIndex='<%# SetIndex(Container.DataItem("ItemType"))
%>'/>
</ItemTemplate>
</asp:TemplateColumn>
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
2 1258
How bout using code akin to this...

Dim TheItem As String="Some Value"

' select that value in drop downlist
Dim MyListItem As ListItem = ddl.Items.FindByValue(TheItem)
ddl.SelectedIndex = ddl.Items.IndexOf(MyListItem)

HTH,
Greg

"naija naija" <pa*********@crazyjohns.com.au> wrote in message
news:OC**************@tk2msftngp13.phx.gbl...
Hi Guys,
I have my .aspx below and i'm using SetIndex with selectedIndex
with DropDownList to retrieve Data from my database!!
My function of SetIndex is as follows:-
Function SetIndex(ByVal TheItem As String)

Dim ItemTypes As ArrayList
Dim i As Integer
For i = 0 To ItemTypes.Count - 1
If TheItem = ItemTypes(i) Then
Return i
End If
Next
End Function

When i compile it using VS.NET it comoiles but when i run it i get error
"Name 'ItemTypes' is not declared"
Do i have to still delcare ItemTypes some how..
Pls help!!

My Asp.Net
------------
<asp:TemplateColumn>
<HeaderTemplate>
Type<br>
<asp:DropDownList id="ItemType" runat="server"
DataSource='<%# ItemTypes %>'/>
</HeaderTemplate>
<ItemTemplate>
<asp:DropDownList id="Dropdownlist1" runat="server"
DataSource='<%# ItemTypes %>'
SelectedIndex='<%# SetIndex(Container.DataItem("ItemType"))
%>'/>
</ItemTemplate>
</asp:TemplateColumn>
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2
Thanks for the reply Greg but have:-
ItemTypes = New ArrayList
DBConnection = New SqlConnection("")
DBConnection.Open()
SQLString = "SELECT DISTINCT ItemType FROM products1 ORDER BY
ItemType"
DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
While DBReader.Read()
ItemTypes.Add(DBReader("ItemType"))
End While
DBReader.Close()
DBConnection.Close()

I'm using VS.Net do i have to declare something using Protected WithEvents ?
Now i get the error:-"System.NullReferenceException: Object reference not
set to an instance of an object."
Saying there is na error on the line:- "For i = 0 To ItemTypes.Count - 1"
Any advice?
"Greg Burns" wrote:
How bout using code akin to this...

Dim TheItem As String="Some Value"

' select that value in drop downlist
Dim MyListItem As ListItem = ddl.Items.FindByValue(TheItem)
ddl.SelectedIndex = ddl.Items.IndexOf(MyListItem)

HTH,
Greg

"naija naija" <pa*********@crazyjohns.com.au> wrote in message
news:OC**************@tk2msftngp13.phx.gbl...
Hi Guys,
I have my .aspx below and i'm using SetIndex with selectedIndex
with DropDownList to retrieve Data from my database!!
My function of SetIndex is as follows:-
Function SetIndex(ByVal TheItem As String)

Dim ItemTypes As ArrayList
Dim i As Integer
For i = 0 To ItemTypes.Count - 1
If TheItem = ItemTypes(i) Then
Return i
End If
Next
End Function

When i compile it using VS.NET it comoiles but when i run it i get error
"Name 'ItemTypes' is not declared"
Do i have to still delcare ItemTypes some how..
Pls help!!

My Asp.Net
------------
<asp:TemplateColumn>
<HeaderTemplate>
Type<br>
<asp:DropDownList id="ItemType" runat="server"
DataSource='<%# ItemTypes %>'/>
</HeaderTemplate>
<ItemTemplate>
<asp:DropDownList id="Dropdownlist1" runat="server"
DataSource='<%# ItemTypes %>'
SelectedIndex='<%# SetIndex(Container.DataItem("ItemType"))
%>'/>
</ItemTemplate>
</asp:TemplateColumn>
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 18 '05 #3

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

Similar topics

0
by: Patrick.O.Ige | last post by:
If i use (How would i declare SetIndex or would i have to declare DopDownList or TemplateColumn in Visual Studio .Net) :- Thx for the help in advance!!! Function SetIndex(TheItem As String)...
3
by: Tim::.. | last post by:
Can someone please tell my why the following doesn't work! I don't get any errors on the page but when I choose a value from the dropdownlist what is ment to happen is that a user control should...
1
by: vladp | last post by:
Hi! Here is problem I got. I use vb.net and MSSQL Server 2000. My dropdownlist box gets information from view, and it works. However when I am trying to get information from the dropdownlist I...
3
by: Mark Rae | last post by:
Hi, Apologies, but I appear to be having a senior moment... I have a standard DropDownList webcontrol with a SelectedIndexChanged event, as follows: <asp:TableCell ColumnSpan=4...
4
by: glenn | last post by:
Hi folks, I am getting an error "Object reference not set to an instance of an object". It seems I have everything in place but something is obviously in err. If you could take a quick peak...
8
by: Rick | last post by:
I have been trying to get this dropdownlist to run and I am having nothing but errors. Anyone know what I am doing wrong? Any help would be much appreciated!!! Here is my code. <script...
3
by: Mark Rae | last post by:
Hi, Is it possible to use a Dictionary<int, stringor even Dictionary<string, stringas the DataSource for a DropDownList directly, i.e. without having to iterate through the the Dictionary's...
5
by: =?Utf-8?B?Q2hyaXMgRy4=?= | last post by:
I'm trying to put conditional code in a dropdown that would check the value of the current ListItem and set Selected=true depending on that value, and Selected=false if it's any other value. Due...
2
by: steven | last post by:
i've got a dropDownList that I'm trying to populate from my code behind as follows: uxVehicleColourEdit.DataSource = oDsLookups.Tables; if the dropDown is placed inside a datagrid, i get...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
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,...

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.