• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

dropdownlist1 selected item

While tildays > 0
            DropDownList1.Items.Add(tildays)

            tildays -= 0.5
        End While

Open in new window


i current use the above to populate the dropdown menu but when i use DropDownList1.SelectedValue.ToString i get a blank value
0
runnerjp2005
Asked:
runnerjp2005
  • 7
  • 4
1 Solution
 
zvytasCommented:
Change the code to the following:

While tildays > 0
            DropDownList1.Items.Add(tildays, tildays)

            tildays -= 0.5
        End While

Open in new window

0
 
runnerjp2005Author Commented:
i get the error

Overload resolution failed because no accessible 'Add' accepts this number of arguments.
0
 
CodeCruiserCommented:
Try changing to

DropDownList1.Items.Add(New ListItem(tildays, tildays))
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
runnerjp2005Author Commented:
Ok for some reason i dont get any results from the drop down menu from my code:

 Protected Sub tilbooking_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles tilbooking.Click

        '##############################################
        '# remove all panels but the til booking one  #
        '##############################################

        tiltab.Visible = True
        Panelcalander.Visible = False
        Countdown.Visible = False
        tilbooking.Visible = False
        holidaysubmit.Visible = False
        trainingbooking.Visible = False


        storeddate = CType(Session("storeddate"), Dictionary(Of DateTime, String))
        Dim pair As KeyValuePair(Of DateTime, String)
        Dim res As List(Of String) = checkforholidays.gethols()
        For Each pair In storeddate
            thedate.Text = pair.Key

            If pair.Value = "full" Then
                ampmfull.Visible = True
                ampmlabel.Visible = True
                ampmlabel.Text = "Am or Pm: "
            Else
                ampmfull.Visible = False
                ampmlabel.Visible = True
                ampmlabel.Text = "You Have Selected " & pair.Value
            End If

        Next
        Dim tildays As Decimal = dateallreadybooked.counttilleft("Jarratt")

        While tildays > 0
            DropDownList1.Items.Add(New ListItem(tildays, tildays))

            tildays -= 0.5
        End While

    End Sub

    Protected Sub canceltil_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles canceltil.Click
        '##################################################
        '# switch panels back so you can see the calender #
        '##################################################
        tiltab.Visible = False
        Panelcalander.Visible = True
        Countdown.Visible = True
        tilbooking.Visible = True
        holidaysubmit.Visible = True
        trainingbooking.Visible = True
    End Sub

    Protected Sub booktil_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles booktil.Click
        '##################################################################
        '# send an email to superusers to say they are requesting the til #
        '##################################################################
       
        '################################################
        '# add the til request to the db to be approved #
        '################################################
        storeddate = CType(Session("storeddate"), Dictionary(Of DateTime, String))
        Dim pair As KeyValuePair(Of DateTime, String)
        For Each pair In storeddate
            '  tilrequest.addtilrequest(DateTime.Parse(pair.Key), pair.Value.ToString, Session("t"))
        Next

        '########################################################
        '# minus the til request from the users til under users #
        '########################################################

        MsgBox(DropDownList1.SelectedValue.ToString)

        ' tilrequest.deletetil(Session("t"))

        '##################################################
        '# switch panels back so you can see the calender #
        '##################################################
        tiltab.Visible = False
        Panelcalander.Visible = True
        Countdown.Visible = True
        tilbooking.Visible = True
        holidaysubmit.Visible = True
        trainingbooking.Visible = True



    End Sub
End Class

Open in new window


0
 
CodeCruiserCommented:
>Ok for some reason i dont get any results from the drop down menu from my code:
Do you mean the dropdown is not populated or do you mean you dont get the value?
0
 
runnerjp2005Author Commented:
i dont get a value
0
 
CodeCruiserCommented:
> MsgBox(DropDownList1.SelectedValue.ToString)
You are using a msgbox in ASP.NET? Did you try to step through the code?
0
 
runnerjp2005Author Commented:
yup and it should pick up the number.... here is the full code if it helps

Protected Sub tilbooking_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles tilbooking.Click

        '##############################################
        '# remove all panels but the til booking one  #
        '##############################################

        tiltab.Visible = True
        Panelcalander.Visible = False
        Countdown.Visible = False
        tilbooking.Visible = False
        holidaysubmit.Visible = False
        trainingbooking.Visible = False


        storeddate = CType(Session("storeddate"), Dictionary(Of DateTime, String))
        Dim pair As KeyValuePair(Of DateTime, String)
        Dim res As List(Of String) = checkforholidays.gethols()
        For Each pair In storeddate
            thedate.Text = pair.Key

            If pair.Value = "full" Then
                ampmfull.Visible = True
                ampmlabel.Visible = True
                ampmlabel.Text = "Am or Pm: "
            Else
                ampmfull.Visible = False
                ampmlabel.Visible = True
                ampmlabel.Text = "You Have Selected " & pair.Value
            End If

        Next
        Dim tildays As Decimal = dateallreadybooked.counttilleft("Jarratt")

        While tildays > 0
            DropDownList1.Items.Add(New ListItem(tildays, tildays))

            tildays -= 0.5
        End While

        Session("test") = DropDownList1.SelectedValue.ToString
    End Sub

    Protected Sub canceltil_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles canceltil.Click
        '##################################################
        '# switch panels back so you can see the calender #
        '##################################################
        tiltab.Visible = False
        Panelcalander.Visible = True
        Countdown.Visible = True
        tilbooking.Visible = True
        holidaysubmit.Visible = True
        trainingbooking.Visible = True
    End Sub

    Protected Sub booktil_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles booktil.Click
        '##################################################################
        '# send an email to superusers to say they are requesting the til #
        '##################################################################
       
        '################################################
        '# add the til request to the db to be approved #
        '################################################
        ' storeddate = CType(Session("storeddate"), Dictionary(Of DateTime, String))
        ' Dim pair As KeyValuePair(Of DateTime, String)
        '  For Each pair In storeddate
        '  tilrequest.addtilrequest(DateTime.Parse(pair.Key), pair.Value.ToString, Session("t"))
        '   Next

        '########################################################
        '# minus the til request from the users til under users #
        '########################################################

        ' tilrequest.deletetil(Session("t"))

        '##################################################
        '# switch panels back so you can see the calender #
        '##################################################
        ' tiltab.Visible = False
        'Panelcalander.Visible = True
        ' Countdown.Visible = True
        'tilbooking.Visible = True
        'holidaysubmit.Visible = True
        'trainingbooking.Visible = True



    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label4.Text = Session("test")
    End Sub

Open in new window



<%@ Page Title="Service Desk Calendar" Language="VB" MasterPageFile="~/intranet.master" AutoEventWireup="false" CodeFile="Calendar.aspx.vb" Inherits="Calendar" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
              .fltright
        {
            float: right;
            clear: both;
            
                   }
       .hide
        {
          display:none;
        }
        a img
      {
        border: none;
      }
      .countdownbox
      {
          border:2.5px solid black;
            width: 300px;
            margin-top:10px;
            margin-bottom:10px;
            padding:5px;
            background-color:#003366;
            color:White;
        }
       #deletepanel
       {
           text-align:center;
           padding:10px;
       }
      .transparent {
    filter:alpha(opacity=90);
    background-color:#003366;
    display:none;
    width:170;
    height:100;
    position:absolute;
    color: white;
    border: 1 green solid;
}
    </style>
    <script>
        /* this function shows the pop-up when
        user moves the mouse over the link */
        function Show() {
            /* get the mouse left position */
            x = event.clientX + document.body.scrollLeft;
            /* get the mouse top position  */
            y = event.clientY + document.body.scrollTop + 35;
            /* display the pop-up */
            Popup.style.display = "block";
            /* set the pop-up's left */
            Popup.style.left = x;
            /* set the pop-up's top */
            Popup.style.top = y;
        }
        /* this function hides the pop-up when
        user moves the mouse out of the link */
        function Hide() {
            /* hide the pop-up */
            Popup.style.display = "none";
        }
</script>
    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Panel ID="Panelcalander" runat="server">   
        <asp:Calendar  ID="Calendar1" runat="server" BackColor="#003366" 
        BorderColor="Black" BorderStyle="Solid" CellSpacing="1" Font-Names="Verdana" 
        Font-Size="8pt" ForeColor="Black" Height="253px" NextPrevFormat="ShortMonth" 
        Width="100%">
        <DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="white" 
            Height="5pt" />
        <DayStyle BackColor="white" />
        <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" />
        <OtherMonthDayStyle ForeColor="#999999" />
        <SelectedDayStyle BackColor="white" ForeColor="black" />
        <TitleStyle  CssClass="calborder" BackColor="#003366" BorderStyle="Solid" Font-Bold="True" 
            Font-Size="12pt" ForeColor="White" Height="12pt" />
        <TodayDayStyle BackColor="white" ForeColor="red" />
     
    </asp:Calendar>  
    <div id="Popup" class="transparent">
    <div style="background-color: #003366">
      <b> Holidays booked On  
          <asp:Label ID="tooltipdate" runat="server"></asp:Label> </b></div>
    <div><br />
        <asp:Label ID="tooltiptext" runat="server"></asp:Label></div>
</div>     
        </asp:Panel>
     <asp:Panel ID="Panelerror" runat="server" Visible="false">
     <div id="deletepanel">
        <asp:Label ID="theerror" runat="server"></asp:Label><br />
        <asp:Button ID="Ok" runat="server" Text="Ok" Visible="false" />
        <asp:Button ID="Cancel" runat="server" Text="Cancel" Visible="false"  />         
        </div>
    </asp:Panel>
        <asp:Panel ID="tiltab" runat="server" Visible="false">
        <center>
        <div id="tiltab2">
            <br />
            Date Selected: <asp:Label ID="thedate" runat="server" Text="Label"></asp:Label> <br /><br />
         
            <asp:Label ID="ampmlabel" runat="server" Visible="false"></asp:Label> <asp:DropDownList Visible="false" ID="ampmfull" runat="server">
                <asp:ListItem>Am</asp:ListItem>
                <asp:ListItem>Pm</asp:ListItem>
            </asp:DropDownList> <br />  
             No Of Hours: <asp:DropDownList ID="DropDownList1" runat="server" 
                EnableViewState="False">   
             </asp:DropDownList> <br />  <br />  
             Comments:<br /> <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" 
                Height="78px" Width="319px"></asp:TextBox>
            <br />
        
            <br />
            Please note that this will need to be approved before shown on the calender.<br />
            <br />
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
                    <asp:Button ID="Button1" runat="server" Text="Button" />
                </ContentTemplate>
            </asp:UpdatePanel>
            <br /> <br /> 
              
            <asp:Button ID="booktil" runat="server" Text="Book Til" />
            <asp:Button ID="canceltil" runat="server" Text="Cancel" />
                 </div>  </center>
    </asp:Panel>

    <asp:ImageButton ID="CalendarLinkButton" Visible="true" runat="server" CssClass="hide"  >
        </asp:ImageButton>  

  
<center>
<br />
    <asp:imagebutton ID="tilbooking" runat="server" Text="booktil" Visible = "true"  ImageUrl="~/images/booktil.jpg" />
    <asp:imagebutton ID="holidaysubmit" Visible="false" runat="server" Text="Submit" 
        ImageUrl="~/images/bookholiday.jpg" />
         <asp:imagebutton ID="trainingbooking" runat="server" Text="booktil"  ImageUrl="~/images/booktraining.jpg" />
  
    <asp:Panel ID="Countdown" runat="server">
    <div class="countdownbox">
        <asp:Label ID="Countdownlabel" runat="server" ></asp:Label></div>
     <div class="countdownbox">
        <asp:Label ID="tilleft" runat="server" ></asp:Label>
        </div>
    </asp:Panel></center>
  <asp:Label ID="Label1" runat="server"></asp:Label>
    <asp:Label ID="Label2" runat="server" ></asp:Label>


















    <asp:Label ID="Label3" runat="server" ></asp:Label>


















</asp:Content>

Open in new window

0
 
runnerjp2005Author Commented:
it now seems to always select the top value but not the value selected
0
 
CodeCruiserCommented:
Its because you are checking the selected value straight after populating the list. Test it after the page renders and you select a value from the list.
0
 
runnerjp2005Author Commented:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Label4.Text = DropDownList1.SelectedItem.Text


    End Sub

Open in new window


i have done it on button click and i still get the top value?
0
 
runnerjp2005Author Commented:
the issue was with my view state been off ><
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now