Malespissus
New Member
This is what I have on the page_load. However, when I select a value from the dropdown, it never retains the value i want. As a result I always get the same results. Any ideas?<BR><BR> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> 'Put user code to initialize the page here <BR> Dim cmd As SqlCommand<BR> Dim da As New SqlDataAdapter()<BR> Dim dt As New DataTable()<BR> Dim con As New SqlConnection(cfg.GetConnString())<BR><BR> Dim sSQL As String<BR> sSQL = "SELECT -4 AS SiteID, 'Center' as FranchiseDisplay, '' AS Franchise UNION ALL " & _<BR> "SELECT -3 AS SiteID, '-----------------------' AS FranchiseDisplay, '' AS Franchise UNION ALL " & _<BR> "SELECT DISTINCT SiteID, Franchise AS FranchiseDisplay, Franchise FROM tblSiteData ORDER BY Franchise, SiteID"<BR><BR> cmd = con.CreateCommand<BR> cmd.CommandType = CommandType.Text<BR> cmd.CommandText = sSQL<BR><BR> da.SelectCommand = cmd<BR> con.Open()<BR><BR> da.Fill(dt)<BR><BR> ddlSelectFranchise.DataSource = dt<BR> ddlSelectFranchise.DataTextField = "FranchiseDisplay"<BR> ddlSelectFranchise.DataValueField = "SiteID"<BR> ddlSelectFranchise.DataBind()<BR><BR> con.Close()<BR><BR> End Sub<BR><BR> Public ReadOnly Property Center() As String<BR> Get<BR> Return ddlSelectFranchise.SelectedItem.Value<BR> End Get<BR> End Property<BR><BR><BR>The value is always the same and never the one I selected. I'm stumped on this one. Any help would be great.Hi mrack,<BR><BR>I also encountered this problem.<BR>You can very easily solve this problem. When you are populating the dropdownlist DON'T do that on the Page_Load but in the Page_Init fase. The most logical way is populate the dropdownlist during initialisation, that means in the Page_Init and not the Page_Load.<BR><BR>Good luck.<BR><BR>UltimaWhat you need is a <BR>If not ispostback then<BR><BR>end if<BR>around your code. Every time the page loads it is rebuilding the drop down. You don't need to rebuild it in asp.net, just build it once.Thanks, let me give both of those a try. Much appreciated for the replies.