selectedindex changed event & oracledatareader problem

  • Thread starter Thread starter drdave
  • Start date Start date
D

drdave

Hi,

I have a dropdown list (ddljurisdiction) that when the selectedindex
changed event is fired fills a oracledatareader that fills other
dropdowns.. this works fine on the first event..

however on the form if the user selects another value from
ddljurisdiction, the dropdowns that are filled the results have
doubled, another click and the results triple..

I was thinking I should try and databind the dropdowns but I dont
really understand this current behaviour.. if anyone has ideas to fix
here is my code:

Private Sub ddljurisdiction_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddljurisdiction.SelectedIndexChanged


If Me.ddljurisdiction.SelectedItem.Text = "Provincial" Then

Me.ddlProvinces.Visible = True

Else

Me.ddlProvinces.Visible = False
Me.ddlrate_type.Visible = False

End If


Me.ddlVariations.Visible = True
Me.ddlrate_type.Visible = True
Me.btnAddRecord.Visible = True



Dim Conn As New OracleConnection
(ConfigurationSettings.AppSettings("connectionstring"))
Conn.Open ()
' Create Command Object
Dim cmd As OracleCommand = New OracleCommand
("mwadmin_pkg.GetReadOnlyData",Conn)

'Stored Procedure
cmd.CommandType = CommandType.StoredProcedure


'Create Parameter Objects
cmd.Parameters.Add ("province_cursor", OracleDBType.RefCursor)
cmd.Parameters.Add ("variation_cursor", OracleDBType.RefCursor)
cmd.Parameters.Add ("rate_type_cursor", OracleDBType.RefCursor)
cmd.Parameters.Add ("minimum_wage_cursor", OracleDBType.RefCursor)


cmd.Parameters(0).Direction = ParameterDirection.Output
cmd.Parameters(1).Direction = ParameterDirection.Output
cmd.Parameters(2).Direction = ParameterDirection.Output
cmd.Parameters(3).Direction = ParameterDirection.Output



Dim int As Integer
int = cmd.ExecuteNonQuery()


Dim rdr1 As OracleDataReader
Dim rdr2 As OracleDataReader
Dim rdr3 As OracleDataReader



Try
' use the 3 REF CURSORs at the same time

rdr1 = (CType(cmd.Parameters(0).Value,OracleRefCursor)).GetDataReader()


While rdr1.Read()
Dim prov_list As ListItem = New ListItem
prov_list.Text = rdr1("ENGLISH_NAME")
prov_list.Value = rdr1("province_id").ToString
ddlProvinces.Items.Add(prov_list)

End While

rdr1.Close ()
rdr1.Dispose ()

rdr2 = (CType(cmd.Parameters(1).Value,OracleRefCursor)).GetDataReader()


While rdr2.Read()


Dim var_list As ListItem = New ListItem
var_list.Text = rdr2("ENGLISH_TEXT")

var_list.Value =
rdr2("MINIMUM_WAGE_VARIATION_ID").ToString
ddlVariations.Items.Add(var_list)

End While
rdr2.Close()
rdr2.Dispose()



rdr3 =
(CType(cmd.Parameters(2).Value,OracleRefCursor)).GetDataReader()


While rdr3.Read()

Dim rate_list As ListItem = New ListItem
rate_list.Text = rdr3("ENGLISH_NAME")

rate_list.Value = rdr3("RATE_TYPE_ID").ToString
ddlrate_type.Items.Add(rate_list)

End While


Catch ex As Exception
Response.Write (ex)

Finally
rdr1.Close()
rdr2.Close()
rdr3.Close()
conn.Close ()
conn.Dispose()

End Try


End Sub

tia

Dave
 
It looks like it's happening because you keep adding items to the list
boxes. Easy solution.. Clear them

I think this is the right method, doing it from memory

ddlProvinces.Items.Clear()

While rdr1.Read()
Dim prov_list As ListItem = New ListItem
prov_list.Text = rdr1("ENGLISH_NAME")
prov_list.Value = rdr1("province_id").ToString
ddlProvinces.Items.Add(prov_list)
End While

Chris
 
Back
Top