Solved

ASP.net Populate Dropdown List with session variable

Posted on 2007-11-13
6
740 Views
Last Modified: 2013-11-26
I currently have a dropdown list (txtStatusNew.text ) that holds all of the Status Types of our projects. How do I show the Current Status of the Project in the Drop down list as well as all of the other choices available.

The Datasource for the dropdown list is this:
        SelectCommand="SELECT [StatusID], [StatusType] FROM [tblStatus]"></asp:SqlDataSource>


The Project Record data is being pulled into the page like this:

         Dim SelectCommand As String
                SelectCommand = String.Format("SELECT tblProjects.ProjectID, tblProjects.PlanStartDate, tblProjects.PlanDueDate, tblProjects.Notes, tblProjects.ProjectTitle, tblDepartments.DepartmentName,tblReasonCodes.Reason, tblRequestor.FirstName + ' ' + tblRequestor.LastName AS Requestor,tblWorkers.WorkerFirstName + ' ' + tblWorkers.WorkerLastName AS Resource, tblStatus.StatusType, tblProjects.RequestedCompletionDate,tblProjects.FileLocation, tblProjects.EstimatedHours, tblProjects.ProjectActualHours FROM tblProjects INNER JOIN tblStatus ON tblProjects.StatusID = tblStatus.StatusID LEFT OUTER JOIN tblRequestor ON tblProjects.RequestorID = tblRequestor.RequestorID LEFT OUTER JOIN tblWorkers ON tblProjects.WorkerID = tblWorkers.WorkerID LEFT OUTER JOIN tblReasonCodes ON tblProjects.ReasonCode = tblReasonCodes.ReasonCode LEFT OUTER JOIN tblDepartments ON tblProjects.DepartmentID = tblDepartments.DepartmentID WHERE tblProjects.ProjectID = {0}", Request.QueryString("ProjectID"))
                Using comm As New SqlCommand(SelectCommand, conn)
                    Dim rs As SqlDataReader = comm.ExecuteReader()
                    If rs.Read() Then
                        txtProjectID.Text = rs("ProjectID").ToString()
                        txtProjectTitle.Text = rs("ProjectTitle").ToString()
                        txtResource.Text = rs("Resource").ToString()
                        txtStartDate.Text = rs("PlanStartDate").ToString()
                        txtDueDate.Text = rs("PlanDueDate").ToString()
                        txtDept.Text = rs("DepartmentName").ToString()
                        txtRequestor.Text = rs("Requestor").ToString()
                        lblOldStatus.Text = rs("StatusType").ToString()
                        lblOldReason.Text = rs("Reason").ToString()
                        txtEstHours.Text = rs("EstimatedHours").ToString()
                        txtActHours.Text = rs("ProjectActualHours").ToString()
                        txtNotes.Text = rs("Notes").ToString()
                       
                       
                        conn.Close()
                    End If
                End Using
            End Using
0
Comment
Question by:Albee_J
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 16

Accepted Solution

by:
anoyes earned 500 total points
ID: 20276770
Give this a shot:

txtStatusNew.SelectedValue=rs("StatusID").ToString

where StatusID is the name of the field in the tblProjects table that stores the current status.
0
 

Author Comment

by:Albee_J
ID: 20276856
I will give this a shot tomorrow morning at work.  Won't that code only show the current status without the rest of the status types in the drop down list?
0
 
LVL 16

Expert Comment

by:anoyes
ID: 20276877
As long as you bind the drop down list to your SELECT [StatusID], [StatusType] FROM [tblStatus] first, it should work fine.  Bind first, then the .SelectedValue just specifies which one of those values should be selected when the page first loads.  Let me know if you need further clarification.

-Adam
0
Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

 

Author Comment

by:Albee_J
ID: 20280242
I am getting this error

 StatusID
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.IndexOutOfRangeException: StatusID

Source Error:

Line 32:                         txtActHours.Text = rs("ProjectActualHours").ToString()
Line 33:                         txtNotes.Text = rs("Notes").ToString()
Line 34:                         txtStatusNew.SelectedValue = rs("StatusID").ToString
Line 35:                      
Line 36:                        
0
 
LVL 16

Expert Comment

by:anoyes
ID: 20281320
Sorry, I didn't look close enough at your SQL.  You should also select tblProjects.StatusID.  This will give you the StatusID that is assigned to the project so you can use it to select an option in your drop down list. So SQL should be...

SelectCommand = String.Format("SELECT tblProjects.ProjectID, tblProjects.PlanStartDate, tblProjects.PlanDueDate, tblProjects.Notes, tblProjects.ProjectTitle, tblProjects.StatusID, tblDepartments.DepartmentName,tblReasonCodes.Reason, tblRequestor.FirstName + ' ' + tblRequestor.LastName AS Requestor,tblWorkers.WorkerFirstName + ' ' + tblWorkers.WorkerLastName AS Resource, tblStatus.StatusType, tblProjects.RequestedCompletionDate,tblProjects.FileLocation, tblProjects.EstimatedHours, tblProjects.ProjectActualHours FROM tblProjects INNER JOIN tblStatus ON tblProjects.StatusID = tblStatus.StatusID LEFT OUTER JOIN tblRequestor ON tblProjects.RequestorID = tblRequestor.RequestorID LEFT OUTER JOIN tblWorkers ON tblProjects.WorkerID = tblWorkers.WorkerID LEFT OUTER JOIN tblReasonCodes ON tblProjects.ReasonCode = tblReasonCodes.ReasonCode LEFT OUTER JOIN tblDepartments ON tblProjects.DepartmentID = tblDepartments.DepartmentID WHERE tblProjects.ProjectID = {0}", Request.QueryString("ProjectID"))
0
 

Author Comment

by:Albee_J
ID: 20281634
Great! That worked! :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question