Advertisement

08.27.2008 at 12:05AM PDT, ID: 23681121
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.4

How to set value of dropdownlist by matching text to value from stored proc

Asked by totalgolfnetwork in Programming for ASP.NET, Microsoft Visual Basic.Net

Tags: ,

I have a dropdownlist that I am trying to preselect the value of based on a value returned from a stored proc in the code behind page.  I've tried a few things but nothing is working.  I am populating the dropdownlist from a datasource in the aspx page and then trying to select the appropriate value in the Page_Load according to a value from a stored proc.  

-------------------------------------------
'error message which occurs in line 54

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 52:             email.Text = emailTxt
Line 53:             phone.Text = phoneTxt
Line 54:             statusId.Items.FindByText(statusTxt).Selected = True
Line 55:             comments.Text = commentsTxt
Line 56:
 
--------------------------------------------------------------
'html code for dropdownlist

                                            <asp:DropDownList ID="statusId" runat="server" DataSourceID="SqlDataSource1" DataTextField="status" DataValueField="statusID">
                                            </asp:DropDownList>
                                            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:shcbariatricsConnectionString %>" SelectCommand="procLeadStatus" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

-------------------------------------------------------------------
'relevant code-behind

        If Not (IsPostBack) Then

            Dim datetimeTxt As String = ""
            Dim sourceTxt As String = ""
            Dim referrerTxt As String = ""
            Dim firstnameTxt As String = ""
            Dim lastnameTxt As String = ""
            Dim emailTxt As String = ""
            Dim phoneTxt As String = ""
            Dim statusTxt As String = ""
            Dim commentsTxt As String = ""

            Dim leadId As Integer = Request.QueryString("eid")

            Dim objConn As SqlConnection
            Dim dataReader As SqlDataReader
            Dim strSql As String
            Dim ObjCmd As SqlCommand

            objConn = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("shcbariatricsConnectionString").ConnectionString)
            strSql = "EXECUTE procLeadDetails '" & leadId & "'"
            ObjCmd = New SqlCommand(strSql, objConn)

            objConn.Open()
            dataReader = ObjCmd.ExecuteReader

            If dataReader.Read() Then
                datetimeTxt = dataReader("dateof")
                sourceTxt = dataReader("sourceDescription")
                referrerTxt = dataReader("referrer")
                firstnameTxt = dataReader("firstname")
                lastnameTxt = dataReader("lastname")
                emailTxt = dataReader("email")
                phoneTxt = dataReader("phone1")
                statusTxt = dataReader("status")
                commentsTxt = dataReader("dateof")
            End If

            datetime.Text = datetimeTxt
            source.Text = sourceTxt
            referrer.Text = referrerTxt
            firstname.Text = firstnameTxt
            lastname.Text = lastnameTxt
            email.Text = emailTxt
            phone.Text = phoneTxt
            statusId.Items.FindByText(statusTxt).Selected = True
            comments.Text = commentsTxt

        End If
Start Free Trial
 
Loading Advertisement...
 
[+][-]08.27.2008 at 12:09AM PDT, ID: 22322443

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, Microsoft Visual Basic.Net
Tags: vb.net, Object reference not set to an instance of an object
Sign Up Now!
Solution Provided By: informaniac
Participating Experts: 2
Solution Grade: B
 
 
[+][-]08.27.2008 at 12:11AM PDT, ID: 22322451

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.27.2008 at 01:51AM PDT, ID: 22322841

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628