Solved

dropdownlist1 selected item

Posted on 2011-09-22
12
189 Views
Last Modified: 2012-06-27
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
Comment
Question by:runnerjp2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
12 Comments
 
LVL 5

Accepted Solution

by:
zvytas earned 500 total points
ID: 36581517
Change the code to the following:

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

            tildays -= 0.5
        End While

Open in new window

0
 

Author Comment

by:runnerjp2005
ID: 36581760
i get the error

Overload resolution failed because no accessible 'Add' accepts this number of arguments.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36582110
Try changing to

DropDownList1.Items.Add(New ListItem(tildays, tildays))
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:runnerjp2005
ID: 36586043
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36593808
>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
 

Author Comment

by:runnerjp2005
ID: 36716219
i dont get a value
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36718930
> MsgBox(DropDownList1.SelectedValue.ToString)
You are using a msgbox in ASP.NET? Did you try to step through the code?
0
 

Author Comment

by:runnerjp2005
ID: 36813668
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
 

Author Comment

by:runnerjp2005
ID: 36816074
it now seems to always select the top value but not the value selected
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36817156
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
 

Author Comment

by:runnerjp2005
ID: 36890619
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
 

Author Closing Comment

by:runnerjp2005
ID: 36891049
the issue was with my view state been off ><
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question