|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Help, DropDown Web Control not Retuning "SelectedValue"to obtain the "SelectedValue" in my .aspx page, it returns a blank value. Am I doing something wrong here? This is from my .ascx Page: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Bind_ddlCategoryList() End Sub 'Bind ddl_CategoryList Private Sub Bind_ddlCategoryList() 'Create Database Connection Dim conPlumPortalApps As SqlConnection Dim cmdSQL As SqlCommand Dim drCategories As SqlDataReader conPlumPortalApps = New SqlConnection(ConfigurationSettings.AppSettings("plum_PortalApps_ConnectionString")) cmdSQL = New SqlCommand("SELECT Training_Category_ID, Training_Category FROM Training_Categories ORDER BY Training_Category", conPlumPortalApps) Try conPlumPortalApps.Open() drCategories = cmdSQL.ExecuteReader() ddlCategoryList.DataSource = drCategories ddlCategoryList.DataValueField = "Training_Category_ID" ddlCategoryList.DataTextField = "Training_Category" ddlCategoryList.DataBind() Dim FirstListItem As New ListItem FirstListItem.Text = "" FirstListItem.Value = "" 'Add a blank item at the first position of DropDown. ddlCategoryList.Items.Insert(0, FirstListItem) Catch ex As Exception Response.Write(ex.Message) Finally conPlumPortalApps.Dispose() End Try End Sub Public ReadOnly Property CategoryID() As String Get _CategoryID = ddlCategoryList.SelectedValue Return _CategoryID End Get 'Set(ByVal Value As String) 'End Set End Property Hello Paul,
You are loading the contents of the control every time the page loads, that is why you have no selection. Make sure you check for postback: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If not Page.IsPostback then Bind_ddlCategoryList() End If End Sub ' bind here end if Regards, Visar Gashi, MCP Show quoteHide quote "Paul D. Fox" wrote: > I'm trying to utilize a DropDownList as a User Control however, I when I try > to obtain the "SelectedValue" in my .aspx page, it returns a blank value. > Am I doing something wrong here? > > This is from my .ascx Page: > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > 'Put user code to initialize the page here > > Bind_ddlCategoryList() > > End Sub > > 'Bind ddl_CategoryList > Private Sub Bind_ddlCategoryList() > 'Create Database Connection > Dim conPlumPortalApps As SqlConnection > Dim cmdSQL As SqlCommand > Dim drCategories As SqlDataReader > > conPlumPortalApps = New > SqlConnection(ConfigurationSettings.AppSettings("plum_PortalApps_ConnectionString")) > cmdSQL = New SqlCommand("SELECT Training_Category_ID, > Training_Category FROM Training_Categories ORDER BY Training_Category", > conPlumPortalApps) > > Try > conPlumPortalApps.Open() > drCategories = cmdSQL.ExecuteReader() > > ddlCategoryList.DataSource = drCategories > ddlCategoryList.DataValueField = "Training_Category_ID" > ddlCategoryList.DataTextField = "Training_Category" > > ddlCategoryList.DataBind() > > Dim FirstListItem As New ListItem > FirstListItem.Text = "" > FirstListItem.Value = "" > > 'Add a blank item at the first position of DropDown. > ddlCategoryList.Items.Insert(0, FirstListItem) > > Catch ex As Exception > Response.Write(ex.Message) > Finally > conPlumPortalApps.Dispose() > End Try > End Sub > > Public ReadOnly Property CategoryID() As String > Get > _CategoryID = ddlCategoryList.SelectedValue > Return _CategoryID > End Get > 'Set(ByVal Value As String) > > 'End Set > End Property > > > Ah yes, I forgot about that.
Thanks Show quoteHide quote "Visar Gashi, MCP" <Visar Gashi, M**@discussions.microsoft.com> wrote in message news:6F33EAE9-FF7A-4F17-A561-5A7ECEBD4E41@microsoft.com... > Hello Paul, > > You are loading the contents of the control every time the page loads, > that > is why you have no selection. Make sure you check for postback: > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > 'Put user code to initialize the page here > > If not Page.IsPostback then > Bind_ddlCategoryList() > End If > > End Sub > > ' bind here > end if > > Regards, > Visar Gashi, MCP > > "Paul D. Fox" wrote: > >> I'm trying to utilize a DropDownList as a User Control however, I when I >> try >> to obtain the "SelectedValue" in my .aspx page, it returns a blank value. >> Am I doing something wrong here? >> >> This is from my .ascx Page: >> >> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As >> System.EventArgs) Handles MyBase.Load >> 'Put user code to initialize the page here >> >> Bind_ddlCategoryList() >> >> End Sub >> >> 'Bind ddl_CategoryList >> Private Sub Bind_ddlCategoryList() >> 'Create Database Connection >> Dim conPlumPortalApps As SqlConnection >> Dim cmdSQL As SqlCommand >> Dim drCategories As SqlDataReader >> >> conPlumPortalApps = New >> SqlConnection(ConfigurationSettings.AppSettings("plum_PortalApps_ConnectionString")) >> cmdSQL = New SqlCommand("SELECT Training_Category_ID, >> Training_Category FROM Training_Categories ORDER BY Training_Category", >> conPlumPortalApps) >> >> Try >> conPlumPortalApps.Open() >> drCategories = cmdSQL.ExecuteReader() >> >> ddlCategoryList.DataSource = drCategories >> ddlCategoryList.DataValueField = "Training_Category_ID" >> ddlCategoryList.DataTextField = "Training_Category" >> >> ddlCategoryList.DataBind() >> >> Dim FirstListItem As New ListItem >> FirstListItem.Text = "" >> FirstListItem.Value = "" >> >> 'Add a blank item at the first position of DropDown. >> ddlCategoryList.Items.Insert(0, FirstListItem) >> >> Catch ex As Exception >> Response.Write(ex.Message) >> Finally >> conPlumPortalApps.Dispose() >> End Try >> End Sub >> >> Public ReadOnly Property CategoryID() As String >> Get >> _CategoryID = ddlCategoryList.SelectedValue >> Return _CategoryID >> End Get >> 'Set(ByVal Value As String) >> >> 'End Set >> End Property >> >> >>
SRE (Simple Rule Engine)
Error: Cannot use a leading .. to exit above the top directory. DROPDOWNLIST SELECTEDINDEXCHANGED Drop down listbox - extra properties, possible? REGEX para Email how to capture click event in aspx from placeholder ->control order of usercontrols processed by events of page How do I create an Unordered List (UL) with ASP.NET? Control opens over another I want to do a process once per page process, but 'touch' all instances of my server control. |
|||||||||||||||||||||||