Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

PostBack issue

  Asked By: Bill    Date: Aug 04    Category: Asp.net    Views: 1007
  

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

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Nicolas Costa     Answered On: Aug 04

It seems like the datatable  object "dt" isn't getting persisted on postback.
You're initializing it (by doing the dataadapter.fill) in btnadd_Click( ) -
which occurs during one round trip, but then you're later referencing it in
IndexChanged( ) - which executes during a different round trip. In order
for the datatable object  to have data, you'll need to either fill  it from
the database again, or you'll need to stick it into cache/session
variable/or viewstate after you've filled it the first time. Then when you
want to pull data  out of it in IndexChanged( ), you'll first need to
re-populate it from whichever persisting method  you've used...

 
Didn't find what you were looking for? Find more on PostBack issue Or get search suggestion and latest updates.




Tagged: