F
fredda054
Hi everybody !
I have a little anoying problem with a drop down list in a web app.
the problem is:
I populate a dropdownlist, (ddlCountry), with a dataset containing data
from a db table, (countryID and countryName). to avoid the problem with
having the first item always selected i added a "default" item first by
using:
ddlCountry.Items.Insert(0, "-- select a country --")
everything is working just fine, except if someone for some reason
selects that default row again.
What I do is, I use the valuefield of the dropdownlist, (countryID)
which is an integer, and in the "ddlCountry_SelectedIndexChanged"
eventhandler I use this ID and pases it as a parameter to a function
that retrieves States from the database, based on this countryID. I
fill that info from the db into a dataset and use it to populate a
datagrid, which shows the states of that specific country.
If I select the default item I get the errormessage:
"Input string was not in a correct format"
I thought it would be enough to just make a check in the event handler,
and make sure to do the 'work' only if the value is > 0, but this wont
work for me...
I add the code below, as it was before that check...
could someone please help me to solve this? what check do I have to do
?
What I want is, if the "-- select a country --" is selected again,
nothing should happen. I'm sure this is pretty simple, I'm just to
tired right now see things clearly...
Thanks a lot !!!
Fredrik
The event handler code:
===========================================================
Private Sub ddlCountry_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlCountry.SelectedIndexChanged
Dim objStateBL As New StateBL
Dim CountryID As Integer = ddlCountry.SelectedItem.Value
'this is the line that causes the error
dsState = objStateBL.getStates(CountryID) 'fill the dataset
dgdState.DataSource = dsState
dgdState.DataBind()
dgdState.Visible = True
btnAdd.Visible = True
If dsState.Tables(0).Rows.Count = 0 Then
lblMessage.Visible = True
lblMessage.Text = "No states available for the moment."
End If
End Sub
==============================================================
I have a little anoying problem with a drop down list in a web app.
the problem is:
I populate a dropdownlist, (ddlCountry), with a dataset containing data
from a db table, (countryID and countryName). to avoid the problem with
having the first item always selected i added a "default" item first by
using:
ddlCountry.Items.Insert(0, "-- select a country --")
everything is working just fine, except if someone for some reason
selects that default row again.
What I do is, I use the valuefield of the dropdownlist, (countryID)
which is an integer, and in the "ddlCountry_SelectedIndexChanged"
eventhandler I use this ID and pases it as a parameter to a function
that retrieves States from the database, based on this countryID. I
fill that info from the db into a dataset and use it to populate a
datagrid, which shows the states of that specific country.
If I select the default item I get the errormessage:
"Input string was not in a correct format"
I thought it would be enough to just make a check in the event handler,
and make sure to do the 'work' only if the value is > 0, but this wont
work for me...
I add the code below, as it was before that check...
could someone please help me to solve this? what check do I have to do
?
What I want is, if the "-- select a country --" is selected again,
nothing should happen. I'm sure this is pretty simple, I'm just to
tired right now see things clearly...
Thanks a lot !!!
Fredrik
The event handler code:
===========================================================
Private Sub ddlCountry_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlCountry.SelectedIndexChanged
Dim objStateBL As New StateBL
Dim CountryID As Integer = ddlCountry.SelectedItem.Value
'this is the line that causes the error
dsState = objStateBL.getStates(CountryID) 'fill the dataset
dgdState.DataSource = dsState
dgdState.DataBind()
dgdState.Visible = True
btnAdd.Visible = True
If dsState.Tables(0).Rows.Count = 0 Then
lblMessage.Visible = True
lblMessage.Text = "No states available for the moment."
End If
End Sub
==============================================================