problem with programmatically designed dropdownlist

Discussion in 'ASP .Net' started by Dan, Jul 9, 2007.

  1. Dan

    Dan Guest

    Hi,

    i defined a dropdownlist in code-behind but i can't get the selectedvalue. I
    czn't use autopostback because there are other elements in the form to be
    filled.

    aspx file:
    <asp:DropDownList ID="minw" runat="server">
    </asp:DropDownList>

    <asp:Button ID="Button1" runat="server" />

    code-behind::
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Load
    Dim z As ListItem
    minw.Items.Clear()
    For i = 0 To 200
    z = New ListItem(i, i)
    minw.Items.Add(z)
    Next
    .....

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    Dim mi As Integer
    mi = minw.SelectedValue
    .....

    This returns 0 (first value).
    Thanks
    Dan
     
    Dan, Jul 9, 2007
    #1
    1. Advertising

  2. Check on IsPostBack before populating the ddl. Currently you overwrite it on
    each page load.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Dan" <> wrote in message
    news:%...
    > Hi,
    >
    > i defined a dropdownlist in code-behind but i can't get the selectedvalue.
    > I czn't use autopostback because there are other elements in the form to
    > be filled.
    >
    > aspx file:
    > <asp:DropDownList ID="minw" runat="server">
    > </asp:DropDownList>
    >
    > <asp:Button ID="Button1" runat="server" />
    >
    > code-behind::
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    > Dim z As ListItem
    > minw.Items.Clear()
    > For i = 0 To 200
    > z = New ListItem(i, i)
    > minw.Items.Add(z)
    > Next
    > ....
    >
    > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    > Dim mi As Integer
    > mi = minw.SelectedValue
    > ....
    >
    > This returns 0 (first value).
    > Thanks
    > Dan
    >
     
    Eliyahu Goldin, Jul 9, 2007
    #2
    1. Advertising

  3. Dan

    Ben Rush Guest

    Try only filling the dropdownlist when IsPostBack is false.

    --
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
    Ben Rush
    Microsoft .NET Consultant
    http://www.ben-rush.net/blog
    http://www.sideshowsystems.com


    "Dan" <> wrote in message
    news:%...
    > Hi,
    >
    > i defined a dropdownlist in code-behind but i can't get the selectedvalue.
    > I czn't use autopostback because there are other elements in the form to
    > be filled.
    >
    > aspx file:
    > <asp:DropDownList ID="minw" runat="server">
    > </asp:DropDownList>
    >
    > <asp:Button ID="Button1" runat="server" />
    >
    > code-behind::
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    > Dim z As ListItem
    > minw.Items.Clear()
    > For i = 0 To 200
    > z = New ListItem(i, i)
    > minw.Items.Add(z)
    > Next
    > ....
    >
    > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    > Dim mi As Integer
    > mi = minw.SelectedValue
    > ....
    >
    > This returns 0 (first value).
    > Thanks
    > Dan
    >
     
    Ben Rush, Jul 9, 2007
    #3
  4. Dan

    Dan Guest

    Thanks it works now ...

    "Ben Rush" <ben@sideshowsystemsDOTcom> schreef in bericht
    news:%23%23$...
    > Try only filling the dropdownlist when IsPostBack is false.
    >
    > --
    > ~~~~~~~~~~~~~~~~~~~~~~~~~~
    > Ben Rush
    > Microsoft .NET Consultant
    > http://www.ben-rush.net/blog
    > http://www.sideshowsystems.com
    >
    >
    > "Dan" <> wrote in message
    > news:%...
    >> Hi,
    >>
    >> i defined a dropdownlist in code-behind but i can't get the
    >> selectedvalue. I czn't use autopostback because there are other elements
    >> in the form to be filled.
    >>
    >> aspx file:
    >> <asp:DropDownList ID="minw" runat="server">
    >> </asp:DropDownList>
    >>
    >> <asp:Button ID="Button1" runat="server" />
    >>
    >> code-behind::
    >> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Me.Load
    >> Dim z As ListItem
    >> minw.Items.Clear()
    >> For i = 0 To 200
    >> z = New ListItem(i, i)
    >> minw.Items.Add(z)
    >> Next
    >> ....
    >>
    >> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Button1.Click
    >> Dim mi As Integer
    >> mi = minw.SelectedValue
    >> ....
    >>
    >> This returns 0 (first value).
    >> Thanks
    >> Dan
    >>

    >
    >
     
    Dan, Jul 9, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Skybuck Flying

    Ok cpu designed now what ? ;)

    Skybuck Flying, Aug 2, 2005, in forum: VHDL
    Replies:
    1
    Views:
    530
    Martin Thompson
    Aug 2, 2005
  2. Francis Shanahan

    "Cannot Be Designed" error

    Francis Shanahan, Jul 7, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    441
    Francis Shanahan
    Jul 8, 2003
  3. =?Utf-8?B?Um9iZXJ0?=
    Replies:
    0
    Views:
    466
    =?Utf-8?B?Um9iZXJ0?=
    Apr 6, 2004
  4. Larry Van Der Jagt

    "System.Web.UI.Page' cannot be designed"

    Larry Van Der Jagt, May 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    342
    [MSFT]
    May 5, 2004
  5. =?Utf-8?B?bWVyYWwgZ3V2ZW4=?=

    how to use a user control in web site designed with Visual Studio2

    =?Utf-8?B?bWVyYWwgZ3V2ZW4=?=, Mar 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    383
    =?Utf-8?B?bWVyYWwgZ3V2ZW4=?=
    Mar 9, 2005
Loading...

Share This Page