Error in picking up SelectedIndex from dropdown box

  • Thread starter James D. Marshall
  • Start date
J

James D. Marshall

This is working fine, this is from the page_load subroutine,
'bind System column of SystemInfo table
ddlSystem.DataSource = dsSystemInformation.Tables("SystemInfo")

ddlSystem.DataTextField =
dsSystemInformation.Tables("SystemInfo").Columns("System").ToString

ddlSystem.DataBind()

'populate text boxes with mathing values

PopulateTextBoxes(0)



The PopulateTextboxes works fine
Sub PopulateTextBoxes(ByVal RowID As Integer)
'Assign text property values for the text boxes based on the selectedindex
passed

Dim drw1 As DataRow = dsSystemInformation.Tables("SystemInfo").Rows(RowID)

' What we are doing here is verifying that what is returned from the dataset
is not DBNull,

' if it is true then set the textbox text property to a null string

Dim DBNullCheck As Boolean

Dim PContact As Object = drw1("Primary_Contact")

DBNullCheck = IsDBNull(PContact)

If DBNullCheck = False Then

txtPrimaryContact.Text = PContact

Else

txtPrimaryContact.Text = ""

End If

Dim SContact As Object = drw1("Secondary_Contact")

DBNullCheck = IsDBNull(SContact)

If DBNullCheck = False Then

txtSecondaryContact.Text = SContact

Else

txtSecondaryContact.Text = ""

End If

Dim BHours As Object = drw1("Business_Hours")

DBNullCheck = IsDBNull(BHours)

If DBNullCheck = False Then

txtBusinessHours.Text = BHours

Else

txtBusinessHours.Text = ""

End If

Dim BUnit As Object = drw1("Business_Unit")

DBNullCheck = IsDBNull(BUnit)

If DBNullCheck = False Then

txtBusinessUnit.Text = BUnit

Else

txtBusinessUnit.Text = ""

End If

Dim Dept As Object = drw1("Department")

DBNullCheck = IsDBNull(Dept)

If DBNullCheck = False Then

txtDepartment.Text = Dept

Else

txtDepartment.Text = ""

End If

End Sub



what is not happening is the selectedindex is not being picked up to be
passed to the PopulateTextboxes subroutine, about the only thing I can think
is that I have mixed Windows Form coding with ASP.Net coding
Private Sub ddlSystem_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ddlSystem.SelectedIndexChanged
'call subroutine to fill in the textboxes with the correct information

PopulateTextBoxes(ddlSystem.SelectedIndex)

End Sub
 
S

Scott Allen

James:

Are you saying an event doesn't fire when the user changes the
selected item? You need to set AutoPostBack to true on the
DropDownList for this behavior to happen.
 
J

James D. Marshall

Thanks,
Now I get the row id I was expecting, although now I am getting a different
error, on the first pass the PopulateTextBoxes works just fine, After I
select an entry in the drop down box and pass the selectedindex, I get
Object reference not set to an instance of an object on the drw1.


Its never the big things that get me, its always the small ones, guess this
is what I get for having my hand in 5 or 6 different cookie jars at the same
time.
 
J

James D. Marshall

I think I have stumbled across the issue with the Object reference not set
to an instance of an object, It looks as the dataset is not being persisted
across selections. Is this an issue with using the form designer versus
doing it programmatically?
 
S

Scott Allen

Hi James:

The DataSet won't persist unless you take an explicit step to save it
in a place and bring it back during the next request. You could
requery the database to bring it back, or keep it in Cache or even in
the Session object if need be, Otherwise, when the page finishes
processing the DataSet is lost.
 
J

James D. Marshall

Thanks;
What a difference between working with Windows forms and ASP.NET, not
saying its bad, just different. Just point me in the direction of a good
book or article that will help walk through the process.
 
J

James D. Marshall

Thanks for your assistance,
Have the dataset persisted and populating the text box with the correct
information.
Had to break down and get the big fat book on ASP.NET though, 15 minutes of
reading and it was up and working.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top