troubleshooting Question

Trying to get a Drop Down List to databind in page load

Avatar of Xeavn
Xeavn asked on
ASP.NETVisual Basic.NET
9 Comments1 Solution393 ViewsLast Modified:
I have an ASP.NET page that was originally developed under the 1.1 .NET Framework, and it works correctly with my website. I have been atempting to move these pages over to the newer 2.0 .NET Framework and my drop down list is no longer working correctly. I am not sure what changed between the two frameworks or if I am just missing some simple piece of information, but I can't seem to get this to work.
<div style="float:left;padding-bottom:0.5em;">
	<span>Address Type:<br /></span>
	<asp:DropDownList Id="SearchAddressType"
		DataTextField="AT_NAME"
		DataValueField="AT_ID"
		TabIndex="3"
		RunAt="Server" />
</div>
 
Imports System
Imports System.Collections
Imports System.Text
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
 
Public Class AddressWebForm
    Inherits System.Web.UI.Page
 
    Protected WithEvents SearchAddressType As DropDownList
 
    Protected Sub Page_Load()
        If Session("Username") Is Nothing Then
            Dim myURL As URI = Request.URL
            Response.Redirect("login.aspx?error=timeout&page=" & myURL.Segments(myURL.Segments.Length - 1), False)
        End If
        If Not Page.IsPostBack Then
            SearchAddressType.DataSource() = ot.Data.LoadDataTable("sp_AddressTypeList").DefaultView
            SearchAddressType.DataBind()
            Dim liNone As New ListItem()
            liNone.Text = " "
            liNone.Value = "-1"
            SearchAddressType.Items.Insert(0, liNone)
        End If
    End Sub 'Page_Load
End Class
 
' Load Data Table Function from ot.Data
        Shared Function LoadDataTable(ByVal strSP As String) As System.Data.DataTable
            Dim Data() As String
            Data = strSP.Trim.Split(";"c)
            Dim strQuery As String
            strQuery = Data(0)
            Data = Nothing
 
            Dim objConn As New SqlConnection(CONNECTIONSTRING)
            Dim objCmdSP As New SqlCommand()
 
            If strQuery.StartsWith("SELECT") Then                   'The query is not a stored procedure
                objCmdSP.CommandType = CommandType.Text
                objCmdSP.CommandText = strQuery
            Else
                objCmdSP.CommandType = CommandType.StoredProcedure
                If strQuery.IndexOf(" "c) = -1 Then             'The query is a stored procedure with no arguments
                    objCmdSP.CommandText = strQuery
                Else                                'The query is a stored procedure with arguments
                    Dim mPrms As MatchCollection
                    mPrms = Regex.Matches(strQuery, "\s@\w+=")
                    Dim intCounter As Integer
                    For intCounter = 0 To mPrms.Count - 1
                        Dim intCIndex As Integer
                        intCIndex = mPrms.Item(intCounter).Index
                        Dim intNIndex As Integer
                        If intCounter + 1 < mPrms.Count Then
                            intNIndex = mPrms.Item(intCounter + 1).Index
                        Else
                            intNIndex = strQuery.Length
                        End If
                        Dim strParamName As String
                        strParamName = strQuery.SubString(intCIndex + 1, mPrms.Item(intCounter).Value.Length - 2)
                        Dim strParamValue As String
                        strParamValue = strQuery.SubString(intCIndex + strParamName.Length + 2, intNIndex - intCIndex - strParamName.Length - 2)
                        Dim paramDynamic As New SQLParameter
                        paramDynamic.ParameterName = strParamName
                        If Regex.IsMatch(strParamValue, "^[-+]?\d*(\.\d)?\d*$") And strParamValue.Length <= 9 Then
                            paramDynamic.SqlDbType = SqlDbType.Int
                            paramDynamic.Value = Convert.ToInt32(strParamValue)
                        Else
                            paramDynamic.SqlDbType = SQLDBType.VarChar
                            paramDynamic.Value = strParamValue
                            paramDynamic.Size = strParamValue.Length
                        End If
                        objCmdSP.Parameters.Add(paramDynamic)
                    Next
                    Dim strCT As String() = strQuery.Trim.Split(" "c)
                    objCmdSP.CommandText = strCT(0)
                End If
            End If
 
            Dim objDA As New SqlDataAdapter(objCmdSP)
            objDA.SelectCommand.Connection = objConn
            Dim myDS As New System.Data.DataSet()
            objDA.Fill(myDS)
            Return myDS.Tables(0)
        End Function 'LoadDataTable
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros