Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

[PLAIN]ddl and selected value [Resolved][/PLAIN]

 

I am working on a webpage to pull Patient Xray information.

I have a drop down list to select the correct patient.

I can fill the ddl but I am having trouble capturing the selected item.

After I select the patient I want...I have to select the label and hit Enter to populate the label with the Medical Record number. Can someone look at my code and suggest how to fix this? Thanks

 

Code:

Option Explicit On 
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class WebForm1
   Inherits System.Web.UI.Page
   'Declare a global Connection object 
   Dim objConnection As SqlConnection

#Region " Web Form Designer Generated Code "

   'This call is required by the Web Form Designer.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

   End Sub
   Protected WithEvents ddlTest As System.Web.UI.WebControls.DropDownList
   Protected WithEvents lblMR As System.Web.UI.WebControls.Label

   'NOTE: The following placeholder declaration is required by the Web Form Designer.
   'Do not delete or move it.
   Private designerPlaceholderDeclaration As System.Object

   Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
       'CODEGEN: This method call is required by the Web Form Designer
       'Do not modify it using the code editor.
       InitializeComponent()
   End Sub

#End Region

   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
       Dim objSQLRD As SqlDataReader
       Dim strLName As String
       Dim strFName As String

       'Initialize the Connection Object
       objConnection = New SqlConnection("Server=TestSQL\MISC; Database=xray; User Id = sa; Password=private;")
       'Open the connection to the SQL server
       objConnection.Open()

       strFName = "%J%" 'These will be set from the txtBox on the Form in Live
       strLName = "Roth" 'Just hard coded for testing

       If Not Page.IsPostBack Then
           GetPatientByName(strLName, strFName)
       End If

   End Sub

   Private Sub GetPatientByName(ByVal strLName As String, ByVal strFName As String)
       Dim objSQLCmd As SqlCommand
       Dim objDataAdapter As New SqlDataAdapter
       Dim objDataSet As DataSet

       objSQLCmd = New SqlCommand
       With objSQLCmd
           .CommandText = "sp_GetPatientByName" 'Running this Stored Procedure
           .CommandType = CommandType.StoredProcedure
           .Connection = objConnection  'Using this global defined connector
           .Parameters.Add("@LName", SqlDbType.Char).Value = strLName  'set the parameter
           .Parameters.Add("@FName", SqlDbType.Char).Value = strFName  'set the parameter
       End With

       objDataAdapter = New SqlDataAdapter(objSQLCmd)
       objDataSet = New DataSet
       objDataAdapter.Fill(objDataSet)
       ddlTest.DataSource = objDataSet
       ddlTest.DataTextField = "Full_Name"     'Using a concatenating SELECT in the Stored Proc  
       ddlTest.DataValueField = "Med_Rec#"     'This is the unique field I need to match on
       ddlTest.DataBind()
       ddlTest.Items.Insert(0, "Select a Patient")

   End Sub

   Private Sub ddlTest_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlTest.SelectedIndexChanged
       'Trying to set the selected item to the label on the webform.
       lblMR.Text = ddlTest.SelectedItem.Value
   End Sub
End Class

 

Here is the Stored Proc:

CREATE PROCEDURE sp_GetPatientByName
@LNAME AS VARCHAR(25), @FNAME AS VARCHAR(25)

AS 

SELECT Last_Name + ', ' + First_Name + ': ' +  Med_Rec# AS Full_Name, Med_Rec#
From tblPatient 
WHERE Last_Name Like @LNAME and
First_Name Like @FNAME
GO

 

HTML:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="TestAdvList.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<title>WebForm1</title>
	<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
	<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
	<meta content="JavaScript" name="vs_defaultClientScript">
	<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
	<form id="Form1" method="post" runat="server">
		<asp:dropdownlist id="ddlTest" style="Z-INDEX: 101; LEFT: 200px; POSITION: absolute; TOP: 208px" runat="server"
			Width="256px"></asp:dropdownlist>
		<asp:Label id="lblMR" style="Z-INDEX: 103; LEFT: 232px; POSITION: absolute; TOP: 296px" runat="server"
			Width="192px" Height="24px"></asp:Label></form>
</body>
</HTML>

 

This is just a test project. When I get it right I will move the code to the real project. I know I should close the connections etc.....

Thanks In Advance!

Jeff

Edited by rothjm

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...