Improve company productivity with a Business Account.Sign Up

x
?
Solved

dropdownlist1 selected item

Posted on 2011-09-22
12
Medium Priority
?
197 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
  • 7
  • 4
12 Comments
 
LVL 5

Accepted Solution

by:
zvytas earned 2000 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Watch the video to know the simple way to remove or recover or reset lost or forgotten passwords of Outlook PST file. With Kernel Outlook Password Recovery tool such operation is very easy to perform. It is a freeware with limitation to use with 500…

608 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