I have an aspx page that contains text boxes to hold a
large number of patient data. Some of these text
boxes are parameters for the select statement. When
the user enters data into one of the parameter boxes
and clicks the "Search for Patients" button, the
results are returned in a listbox below. The listbox
contains only a few of the identifying fields for the
patient as opposed to the text boxes that have
everything. I am using a datatable to fill the
listbox. This part works fine.
What I would like to have happen is that when the user
selects one of the items in the listbox, the
corresponding textboxes are filled with the
appropriate information.
What is happening is that when an item in the listbox
is selected the rows in the datatable are lost. What
is the best, (or any), way around this?
My code is listed below:
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
'Public schedule1 As New PBISched()
'Public oItem As Scheduler.CScheduleEl
Public pbiflag As Integer
Public dt, sched As New DataTable()
Public dr As DataRow
Public dsproctable As New DataTable()
#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
End Sub
Private Sub btnadd_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnadd.Click
Dim patient As String
Dim i As Integer
Dim tstlname, tstdob, tstmrn, tstssn As String
Dim tstcount As Integer
Dim recordsaffected As Integer
' SqlConnection1.Open()
tstlname = Me.txtLName.Text
tstdob = Me.txtDOB.Text
tstmrn = Me.txtMRN.Text
tstssn = Me.txtSSN.Text
'Try
SqlDataAdapter1.SelectCommand.Parameters("@lname").Value
= tstlname
SqlDataAdapter1.SelectCommand.Parameters("@dob").Value
= tstdob
SqlDataAdapter1.SelectCommand.Parameters("@mrn").Value
= tstmrn
SqlDataAdapter1.SelectCommand.Parameters("@ssn").Value
= tstssn
recordsaffected = SqlDataAdapter1.Fill(dt)
If recordsaffected > 0 Then
lstPatients.Items.Clear()
For Each dr In dt.Rows
patient = dr("fname").ToString + " "
patient += dr("lname").ToString + "; "
patient += "DOB: " +
dr("dob").ToString + " "
patient += "MRN: " +
dr("mrn").ToString
lstPatients.Items.Add(patient)
Next
Else
'Catch
'lblerror.Text = "No Patients Found.
Patient will be Added."
'lblerror.Visible = True
'Call addapatient()
End If
End Sub
Sub IndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles
lstPatients.SelectedIndexChanged
Dim lstindex, huh As Integer
Dim fname As String
If IsPostBack Then
lstindex = lstPatients.SelectedIndex
'Me.txtFName = dt.DataSet.
'Me.txtFName = dr(lstindex)
Dim myrow As DataRow
Dim myColumn As DataColumn
huh = dt.Rows.Count
fname =
dt.Rows(lstindex)("fname").ToString()
' myrow = dt.Rows(lstindex)
Me.txtLName.Text =
dt.Rows(lstindex)("lname").ToString()
Me.txtFName.Text() =
dt.Rows(lstindex)("fname").ToString()
Me.txtMRN.Text =
dt.Rows(lstindex)("mrn").ToString()
Me.txtDOB.Text =
dt.Rows(lstindex)("DOB").ToString()
Me.txtSSN.Text =
dt.Rows(lstindex)("ssn").ToString()
End If
End Sub