Get SelectedValue of DropDownList in User Control in WebForm

Discussion in 'ASP .Net' started by gu4y, Dec 10, 2003.

  1. gu4y

    gu4y Guest

    Hello All,

    How can I get the SelectedValue of a User Control's DropDownList in the
    code-behind of the WebForm hosting the User Control?

    (Without having to use Request.Form["UserControlName:DropDownListName"])

    Thanks
     
    gu4y, Dec 10, 2003
    #1
    1. Advertising

  2. Expose a public function on your user control that will return this value.

    --
    Chris Jackson
    Software Engineer
    Microsoft MVP - Windows Client
    Windows XP Associate Expert
    --
    More people read the newsgroups than read my email.
    Reply to the newsgroup for a faster response.
    (Control-G using Outlook Express)
    --

    "gu4y" <> wrote in message
    news:...
    > Hello All,
    >
    > How can I get the SelectedValue of a User Control's DropDownList in the
    > code-behind of the WebForm hosting the User Control?
    >
    > (Without having to use Request.Form["UserControlName:DropDownListName"])
    >
    > Thanks
    >
    >
     
    Chris Jackson, Dec 10, 2003
    #2
    1. Advertising

  3. gu4y

    gu4y Guest

    Thanks Chris,

    I exposed a public property and it works great.



    "Chris Jackson" <chrisjATmvpsDOTorgNOSPAM> wrote in message
    news:...
    > Expose a public function on your user control that will return this value.
    >
    > --
    > Chris Jackson
    > Software Engineer
    > Microsoft MVP - Windows Client
    > Windows XP Associate Expert
    > --
    > More people read the newsgroups than read my email.
    > Reply to the newsgroup for a faster response.
    > (Control-G using Outlook Express)
    > --
    >
    > "gu4y" <> wrote in message
    > news:...
    > > Hello All,
    > >
    > > How can I get the SelectedValue of a User Control's DropDownList in the
    > > code-behind of the WebForm hosting the User Control?
    > >
    > > (Without having to use Request.Form["UserControlName:DropDownListName"])
    > >
    > > Thanks
    > >
    > >

    >
    >
     
    gu4y, Dec 10, 2003
    #3
  4. gu4y

    mngates

    Joined:
    Jan 13, 2010
    Messages:
    3
    Problem Exposing Property?

    I have a Web User Control for year, since I will want it to update in the future to include the current year. It contains years from 1970 to the current year.

    The Web User Control will be used in a FormView for the EditItemTemplate. I want to be able to use the SelectedValue property to select the item that is bound to the database.

    No errors appear, but the SelectedValue is not set to the correct year stored in the DB. Can anyone tell me what I'm doing wrong?

    Thanks so much in advance!
    Here is the code.

    In EditItemTemplate, the included User Control:


    <uc1:WUC_DDLYear ID="WUC_DDLYearResolution" runat="server" SelectedValue='<%# year(Eval("Resolution")) %>' />

    The User Control Source:

    <asp:DropDownList ID="DDLYear" runat="server">
    </asp:DropDownList>

    The User Control Code:

    Public Partial Class WUC_DDLYear
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim thisYear As Integer
    For thisYear = 1970 To Year(Now())
    DDLYear.Items.Add(thisYear)
    Next
    End Sub

    Public Property DDLSelectedValue() As String
    Get
    Return DDLYear.SelectedValue
    End Get
    Set(ByVal value As String)
    DDLYear.SelectedValue = value
    End Set
    End Property

    End Class



    Any help is very much appreciated!
     
    mngates, Jan 13, 2010
    #4
  5. gu4y

    mngates

    Joined:
    Jan 13, 2010
    Messages:
    3
    Figured it out.. stupid mistake

    I exposed DDLSelectedValue instead of SelectedValue, but called SelectedValue.

    Sorry for the post, and thanks for reading.
     
    mngates, Jan 13, 2010
    #5
    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. titof
    Replies:
    0
    Views:
    540
    titof
    Jul 24, 2003
  2. Jesse
    Replies:
    3
    Views:
    1,248
    DudeGuy
    Jul 24, 2003
  3. Tom Jorgenson
    Replies:
    3
    Views:
    7,040
  4. Sudhir

    Dropdownlist.SelectedValue ISSUE

    Sudhir, Feb 26, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    468
    Scott Mitchell [MVP]
    Feb 26, 2004
  5. Redhairs
    Replies:
    19
    Views:
    2,993
    Redhairs
    Jan 22, 2008
Loading...

Share This Page