Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > .NET Web Services
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
.NET Web Services Discussions about .NET XML Web Service technologies including ASMX files, WSDL and SOAP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Web Services section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 5th, 2003, 06:57 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select Case

Im having trouble trying to grasp a few things, but the problem im facing @ the moment is trying to display a drop down menu on a select case
following code...

<script language="vb" runat="server">
Sub Page_Load()
  If Page.IsPostBack Then
    Select Case(number.SelectedItem.Value)
      Case "1":
        Message.Text = "<asp:dropdownlist id='list1' runat='server'>" & _
"<asp:listitem>7</asp:listitem>" & _
"<asp:listitem>8</asp:listitem>" & _
"<asp:listitem>9</asp:listitem>" & _
"</asp:dropdownlist>"
      Case "2":
        Message.Text = "hello2"
      Case "3":
        Message.Text = "hello 3"
      Case else
        Message.Text = "0000"
    End Select
  End If
End Sub
</script>

  <form runat="server">
  Select your choice:
  <br><br>
  <asp:radiobuttonlist id="number" runat="server">
    <asp:listitem>1</asp:listitem>
    <asp:listitem>2</asp:listitem>
    <asp:listitem>3</asp:listitem>
  </asp:radiobuttonlist>
  <br><br>
  <input type="submit" value="Submit Choice">
  <br><br>
  <asp:label id="message" runat="server"/>
</form>

the code works, but if you choose case 1 it does not display a drop down menu it will just write "789" any help with this matter would be a great help.




Reply With Quote
  #2 (permalink)  
Old July 5th, 2003, 08:05 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

An <asp:listitem> control runs at the server, and therefore needs to be created at the server. What you are doing now is create a text string that you push to the client. If you look at the source in the browser, you'll see that the <asp:listitem> tags are still there. Since a browser ignores tags it doesn't understand (the listitem in this case), only the numbers between the tags are shown.

What you need to do is create a real drop down and add that to your page.

One of the ways to this is as follows:

1. Create an empty drop down control at the location where you need the drop-down and set its Visible property to hidden.

2. In your Select Case statement, add the following code:

Code:
Dim oListItem As ListItem = New ListItem()
oListItem.Value = "9"
oListItem.Text = "9"
MyDropDown.Items.Insert(0, oListItem)

oListItem = New ListItem()
oListItem.Value = "8"
oListItem.Text = "8"
MyDropDown.Items.Insert(0, oListItem)

oListItem = New ListItem()
oListItem.Value = "7"
oListItem.Text = "7"
MyDropDown.Items.Insert(0, oListItem)

MyDropDown.Visible = True
This code creates three new list items, adds them to the DropDown at run time and then sets the DropDown's Visible property to True.

There are more compact ways to add the code then this (for example, use the Add method instead of the Insert method to add new ListItems to the end of a list) but I am sure this should give you enough information to get you going.

Alternatively, you could push a <html> drop-down to the client using the code you have now. In that case, you'll need to replace <asp:dropdownlist> and <asp:listitem> to their HTML equivalent (<select> and <option> respectively). However, in that case it's pretty hard to read their values again back at the server.

HtH

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #3 (permalink)  
Old July 5th, 2003, 08:36 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey thanx for your help, thats got me onto the right track again!

Reply With Quote
  #4 (permalink)  
Old July 10th, 2003, 02:36 AM
Registered User
 
Join Date: Jun 2003
Location: Pantai Remis, Perak, Malaysia.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to samlow82 Send a message via Yahoo to samlow82
Default

If you are not retriving data from database, i recommend you to use ListItem Collection Editor to insert the item.value and item.text. It is error free.
Reply With Quote
  #5 (permalink)  
Old July 10th, 2003, 08:57 PM
Registered User
 
Join Date: Jun 2003
Location: Pantai Remis, Perak, Malaysia.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to samlow82 Send a message via Yahoo to samlow82
Default

As mentioned by Imar, on the pageload u set MyDropDown.Visible = False and then Select Case "1" u set to true.
Did u put AutoPostBack="True" for the dropdown?
Reply With Quote
  #6 (permalink)  
Old July 11th, 2003, 05:42 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok ive tried to do what you told me to do, but it just does not work here is what ive done.......

<script language="vb" runat="server">

Dim oListItem As ListItem = New ListItem()
oListItem.Value = "9" <-----"i get a ERROR msg 'BC30188: Declaration expected' here"
oListItem.Text = "9"
MyDropDown.Items.Insert(0, oListItem)

oListItem = New ListItem()
oListItem.Value = "8"
oListItem.Text = "8"
MyDropDown.Items.Insert(0, oListItem)

oListItem = New ListItem()
oListItem.Value = "7"
oListItem.Text = "7"
MyDropDown.Items.Insert(0, oListItem)





Sub Page_Load()
  If Page.IsPostBack Then
MyDropDown.Visible = false
    Select Case(number.SelectedItem.Value)
      Case "1"
        Message.Text = "true"

      Case "2":
        Message.Text = "hello"
      Case "3":
        Message.Text = "hello2"
          Case Else
        Message.Text = "Error"
   End Select
  End If
End Sub
</script>

  <form runat="server">
  Please select:
  <br><br>
  <asp:listbox id="number" runat="server">
    <asp:ListItem value="1" autopostback="true">DOG</asp:ListItem>
<asp:ListItem value="2">CAT</asp:ListItem>
<asp:ListItem value="3">MOUSE</asp:ListItem>
  </asp:listbox>&nbsp;&nbsp;<asp:label id="message" runat="server"/><asp:label id="MyDropDown" runat="server"/>
<-----"Dont think these are correct"
  <br><br>
  <input type="submit" value="Submit Choice">
  <br><br>

</form>

Thanks for all the help so far very much apreciated


Reply With Quote
  #7 (permalink)  
Old July 11th, 2003, 11:56 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

The error you get is caused by the fact you are running code outside a procedure. Also, not a ListItem has a AutoPostBack property, but the DropDownList itself.

Below you'll find an example that should work. It uses the Visual Studio Code Behind concept (which, IMO is the recommended way to go if you have VS.NET) but I am sure you can change it to suit your situation.

[Page.aspx]
Code:
<form id="Form1" method="post" runat="server">
<asp:DropDownList id=DropDownList1 runat="server" autopostback="True">
  <asp:ListItem Value="1">1</asp:ListItem>
  <asp:ListItem Value="2">2</asp:ListItem>
  <asp:ListItem Value="3">3</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList id=DropDownList2 runat="server" visible="False">
  <asp:ListItem Value="4">4</asp:ListItem>
  <asp:ListItem Value="5">5</asp:ListItem>
  <asp:ListItem Value="6">6</asp:ListItem>
</asp:DropDownList>
<asp:Button id=Button1 runat="server" Text="Button" visible="False"></asp:Button>
</form>
[Page.aspx.vb]
Code:
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
  DropDownList2.Visible = True
  Button1.Visible = True
End Sub
Basically, what happens here is this:

1. At the first hit to the page, both DropDownList2 as the button are hidden (their Visible property is set to False in the page declaration)

2. The AutoPostBack of the first DropDownList is set to True. This will emit some JavaScript to the client, causing the page to submit to the server when the user makes a new selection.

3. When the page is posted, the DropDownList1_SelectedIndexChanged method is fired. In this procedure, DropDownList2 and the button are made visible, by changing their Visible property to True.

4. If you want, the DropDownList1_SelectedIndexChanged method is a nice place to (re)bind the data to DropDownList2. You can, for example, bind it to data from a database, or limit the number of possibilities based on the item the user has chosen in DropDownList1.

HtH

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #8 (permalink)  
Old July 11th, 2003, 01:59 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok, if i understand this correct, it should be as simple as copy and paste the above code??????????????????,(cos it dont work if ive done it right, how stupid of me!)

i made two files 1 called page.aspx and another called page.aspx.vb
i have visual studio.net version 6, but i do want mutiple menus ie.
if the user chooses 1 from the drop downlist then they will get another menu that will display 9 10 11.
if they choose 2 (all using selected method not a submit button, submit button to come into action on the second drop down menu)from the first drop down list they would get 12 13 14..etc...

I know i must be really stupid not to understand this by now, and just wanted to say thankyou for all your help (so far) to everyone thats helped.

Reply With Quote
  #9 (permalink)  
Old July 11th, 2003, 02:55 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi again,

There is no such thing as Visual Studio.NET 6. It's either VS 6 (with "classic ASP", VB6, etc.) or Visual Studio.NET 2002 (also known as 7.0) or 2003 (7.1)

It looks like you're trying to use VS 7 code concepts in a VS 6 solution. That's not going to work, because VS 6 doesn't know or understand ASP.NET.

If you have downloaded the ASP.NET framework, the easiest way to create ASP.NET pages is with inline script (like the example below). The code will be compiled automatically as soon as the pages are requested. VS.NET will compile the page before they are requested by the browser.

I think a good thing to do is to familiarize yourself with the many code examples from the ASP.NET SDK. There are tons of examples, explanations and code snippets to get you going.

Anyway, below you'll find an example that works in a plain ASP.NET page.
Just create a new page with an ASPX extension, paste the entire code in it and run the page. As soon as you select an item from the first list, the second list and the button become visible.

Code:
<%@ Page Language="vb"%>
<script language="vb" runat="server">
  Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, _
        ByVal e As System.EventArgs)
    DropDownList2.Visible = True
    Button1.Visible = True
  End Sub
</script>
<html>
  <head>
    <title>WebForm1</title>
  </head>
  <body >
<form id="Form1" method="post" runat="server">
<asp:dropdownlist id=DropDownList1 runat="server" AutoPostBack="True" 
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
  <asp:listitem value="1">1</asp:listitem>
  <asp:listitem value="2">2</asp:listitem>
  <asp:listitem value="3">3</asp:listitem>
</asp:dropdownlist>
<asp:dropdownlist id=DropDownList2 runat="server" visible="False">
  <asp:listitem value="4">4</asp:listitem>
  <asp:listitem value="5">5</asp:listitem>
  <asp:listitem value="6">6</asp:listitem>
</asp:dropdownlist>
<asp:button id=Button1 runat="server" text="Button" visible="False"></asp:button>
</form>
  </body>
</html>
Notice that because this example does not use VS.NET, you'll need to hook up the DropDownList1_SelectedIndexChanged method to the OnSelectedIndexChanged event yourself in the declaration of the DropDownList.


HtH

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
select case bacster Classic ASP Basics 2 May 1st, 2006 06:31 PM
Select Case junaidraja30 Access VBA 1 February 5th, 2005 08:30 PM
select case yuvalk SQL Server 2000 4 August 25th, 2004 02:33 PM
Select Case morpheus VB How-To 1 August 13th, 2003 09:14 AM
Select Case andy24 Classic ASP Databases 5 July 25th, 2003 07:52 AM



All times are GMT -4. The time now is 02:18 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.