Results 1 to 3 of 3

Thread: Very Simple problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    Very Simple problem

    Hi i don't know why the following doesn't work. I simply have a list of items in an array which i have bound to a dropdownlist.

    Code:
    <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
    <script runat="server">
    Sub Page_Load()
    	If NOT ispostback then
    		Dim ColorArray(4) as String
    		ColorArray(0) = "Blue"
    		ColorArray(1) = "Red"
    		ColorArray(2) = "Green"
    		ColorArray(3) = "Yellow"
    		ColorArray(4) = "Orange"
    		MyDropDownList.DataSource = ColorArray
    		MyDropDownList.DataBind()
    	End if
    End Sub
    
    Sub ColorSelected(Source as Object, E as EventArgs)
    	Dim MyColorText as String
    	MyColorText = MyDropDownList.SelectedItem.text
    	response.write (MyColorText)
    End Sub
    
    </script>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgColor="<%response.write(MyColorText)%>" >
    <form runat="server">
      <asp:dropdownlist ID="MyDropDownList" runat="server"></asp:dropdownlist>
      <asp:button text="Hit Me" onCLick="ColorSelected" runat="server" />
    </form>
    
    </font>
    </body>
    </html>
    Problem is here: bgColor="<%response.write(MyColorText)%>"

  2. #2
    Addicted Member
    Join Date
    Sep 2004
    Posts
    133
    ok, you just need to move the line

    Code:
    Dim MyColorText as String
    outside the Sub so that the variable is declared and available at the page level:

    Code:
    <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
    <script runat="server">
    Sub Page_Load()
    	If NOT ispostback then
    		Dim ColorArray(4) as String
    		ColorArray(0) = "Blue"
    		ColorArray(1) = "Red"
    		ColorArray(2) = "Green"
    		ColorArray(3) = "Yellow"
    		ColorArray(4) = "Orange"
    		MyDropDownList.DataSource = ColorArray
    		MyDropDownList.DataBind()
    	End if
    End Sub
    
    Dim MyColorText as String
       
    Sub ColorSelected(Source as Object, E as EventArgs)
    	MyColorText = MyDropDownList.SelectedItem.text
    	response.write (MyColorText)
    End Sub
    
    </script>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgColor="<%response.write(MyColorText)%>" >
    <form runat="server">
      <asp:dropdownlist ID="MyDropDownList" runat="server"></asp:dropdownlist>
      <asp:button text="Hit Me" onCLick="ColorSelected" runat="server" />
    </form>
    
    </font>
    </body>
    </html>

  3. #3
    New Member
    Join Date
    Sep 2004
    Posts
    9
    You can try this:

    Code:
    Sub ColorSelected(Source as Object, E as EventArgs)
    	response.write (MyDropDownList.SelectedItem.text)
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width