Get SelectedValue of DropDownList in User Control in WebForm

G

gu4y

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
 
G

gu4y

Thanks Chris,

I exposed a public property and it works great.



Chris Jackson said:
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 said:
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
 
Joined
Jan 13, 2010
Messages
3
Reaction score
0
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!
 
Joined
Jan 13, 2010
Messages
3
Reaction score
0
Figured it out.. stupid mistake

I exposed DDLSelectedValue instead of SelectedValue, but called SelectedValue.

Sorry for the post, and thanks for reading.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top