I'm going totally nuts here.
I hope someone can help me here, I've been going nuts for 2 days now.
I have a page where I update and insert items. (for this particular website it's horses.)
Each horse has a lot of properties. I made user controls for all properties.
all user controls contain a simple dropdownlist with inside:
value: an integer (FK to the property table inside the database)
display: the name of the property being read out the db
also before databinding the dropdownlist with values out of the db I've got a hard coded one : "NOT AVAILABLE".
Not available will basically insert NULL inside the database row.
for inserting horses, I simply put an html table inside a panel and put textareas, textbox, and all the user controls there. (I can thus call all these controls directly in my code-behind file)
INSERTING works perfectly. It's the updating part that is making me go nuts:
I now use these user controls as templatefields inside a formview (or detailview, I tried both) for the updating part.
here's a small example:
for inserting, an click-event is fired on the button "new"
all my values are checked or replaced:
here if in my usercontrol, I selected a race that is in the db then it will use that value.
if instead "not available" is selected, the value for "not available" is empty and so a variable sqlintnull is entered.
this @ras is then used as a parameter for my stored procedure. I do this for about 15 parameters.
this work perfectly because these controls are not inside a detailview of formview.
for updating (the information is thus already in the db) I want to display it in a formview of detailview. but if the user clicks "edit" he must be able to change the values.
when in edit mode if the user chooses "not available" in the usercontrol dropdownlist I get an invalid cast to error because inside the dropdownlist it's a STRING and not DBNULL.
this is why I need :
but here instead as in inserted:
(the bold doesn't work!, I cannot seem to get into my public property meaning it doesn't recognises the user control)
ok then I tried this:
I replaced 1 usercontrol with a plain dropdownlist linked to a sqldataconnection.
if I then go to the code behind : (didn't put all the code, just the logic here )
...
and then
it works
so why doesn't this also work on user controls ...
what's the use of usercontrols if this doesn't work
any help would be great
thank you
I hope someone can help me here, I've been going nuts for 2 days now.
I have a page where I update and insert items. (for this particular website it's horses.)
Each horse has a lot of properties. I made user controls for all properties.
all user controls contain a simple dropdownlist with inside:
value: an integer (FK to the property table inside the database)
display: the name of the property being read out the db
also before databinding the dropdownlist with values out of the db I've got a hard coded one : "NOT AVAILABLE".
Not available will basically insert NULL inside the database row.
for inserting horses, I simply put an html table inside a panel and put textareas, textbox, and all the user controls there. (I can thus call all these controls directly in my code-behind file)
INSERTING works perfectly. It's the updating part that is making me go nuts:
I now use these user controls as templatefields inside a formview (or detailview, I tried both) for the updating part.
here's a small example:
for inserting, an click-event is fired on the button "new"
all my values are checked or replaced:
VB.NET:
Dim ras As Object = RaceSelect1.SelectedRace
If Not ras.ToString = String.Empty Then
ras = CInt(RaceSelect1.SelectedRace)
Else
ras = sqlintnull
End If
here if in my usercontrol, I selected a race that is in the db then it will use that value.
if instead "not available" is selected, the value for "not available" is empty and so a variable sqlintnull is entered.
this @ras is then used as a parameter for my stored procedure. I do this for about 15 parameters.
this work perfectly because these controls are not inside a detailview of formview.
for updating (the information is thus already in the db) I want to display it in a formview of detailview. but if the user clicks "edit" he must be able to change the values.
when in edit mode if the user chooses "not available" in the usercontrol dropdownlist I get an invalid cast to error because inside the dropdownlist it's a STRING and not DBNULL.
this is why I need :
VB.NET:
Dim ras As Object = RaceSelect1.SelectedRace
If Not ras.ToString = String.Empty Then
ras = CInt(RaceSelect1.SelectedRace)
Else
ras = sqlintnull
End If
VB.NET:
Dim RaceSelect1 as UserControl = CType(Formview1.FindControl("RaceSelect1"), UserControl)
Dim ras As Object = [B]RaceSelect1.SelectedRace[/B]
If Not ras.ToString = String.Empty Then
ras = CInt(RaceSelect1.SelectedRace)
Else
ras = sqlintnull
End If
ok then I tried this:
I replaced 1 usercontrol with a plain dropdownlist linked to a sqldataconnection.
if I then go to the code behind : (didn't put all the code, just the logic here )
...
VB.NET:
formview1.findcontrol("dropdownlistname")
VB.NET:
dropdownlistname.selectedvalue
so why doesn't this also work on user controls ...
VB.NET:
formview1.findcontrol("usercontrolname")
usercontrolname.publicmethodname
what's the use of usercontrols if this doesn't work
any help would be great
thank you