Bind null data in DropDownList


Author
Message
Vincent C.
Vincent C.
StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)
Group: Forum Members
Posts: 2, Visits: 10
Greg McGuffey (10/03/2008)


Second, setup the TopMostValue of the DropDownList to use the value that is the field's NULL value. I.e. you might set the text to "" and the value to whatever your returning for NULL, like 0. Note that the value is a String, so if you are using a null return value like Integer.MinValue, you probably want to set that in code, otherwise you'll have to type in the actual value.



I hope that was helpful. If not, keep asking questions! BigGrin




Great thanks !



Michel Levy (10/03/2008)


And if you don't want a default value to that combo, do you allow null value in the field c_TypeChamp (in BO mapper), or do you want to check for a value before saving?

Where do you want to check? in the Business Layer, or in the presentation layer?




uh oh wait ... step by step w00t



i learn how to put a null value in database



after that i add a constraint in my SQL Serveur database

ALTER TABLE [dbo].[Championnats] WITH CHECK ADD CONSTRAINT [FK_Championnats_TypeChampionnat] FOREIGN KEY([c_TypeChamp])

REFERENCES [dbo].[TypeChampionnat] ([Code])




and im going to read this article, it sounds great ! Tongue

http://www.atoutfox.org/modules/articles/pdf/0000000630.pdf



Michel Levy (10/03/2008)
and, hem, Doze, why do you learn SF on a web application? AFAIK, your app will be in winforms, and it will be easier (for me BigGrin ) to help you on a win app.




because the application i developp is not for my job, it's for me Wink



Michel Levy
Michel Levy
StrataFrame User (329 reputation)StrataFrame User (329 reputation)StrataFrame User (329 reputation)StrataFrame User (329 reputation)StrataFrame User (329 reputation)StrataFrame User (329 reputation)StrataFrame User (329 reputation)StrataFrame User (329 reputation)StrataFrame User (329 reputation)
Group: StrataFrame Users
Posts: 193, Visits: 9K
Hi Vincent,

glad to meet you here Tongue

Are you sure you have correctly set the "PopulationDataSourceSetting" of your combo? in the Item Population section, your BO would be TypeChampionnat, not Championnat.
As in Fox, SF allows us to double bind combos and lists: 1 binding for value, another one for populating.

And if you don't want a default value to that combo, do you allow null value in the field c_TypeChamp (in BO mapper), or do you want to check for a value before saving?
Where do you want to check? in the Business Layer, or in the presentation layer?

and, hem, Doze, why do you learn SF on a web application? AFAIK, your app will be in winforms, and it will be easier (for me BigGrin ) to help you on a win app.

----

Bonjour Vincent,

content de te retrouver ici Tongue

Est-ce que tu es certain d'avoir correctement renseigné le "PopulationDataSourceSetting" de ton combo? dans la section Item Population, ton BO devrait être TypeChampionnat, et pas Championnat.
C'est comme en Fox, avec SF on a 2 liasons aux données pour les combos et les listes: 1 pour la valeur, et une autre pour la population.

Et si tu ne veux pas de valeur par défaut pour ce combo, est-ce que le champ c_TypeChamp accepte les valeurs nulles (dans le BO mapper), ou bien vas-tu vérifier qu'il y a une valeur saisie avant de sauver? Où veux-tu faire le controle? dans la couche métier, ou dans la couche de présentation?

Et puis, euh, Doze, pourquoi fais-tu ton apprentissage de SF sur une appli web? pour ce que j'en sais, ton appli sera en winforms, alors ça sera plus facile (surtout pour moi BigGrin ) de t'aider sur les winforms.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
If I understand what you are trying to do, you want an option in the drop down list that would represent a NULL value and then you'd like to save that to your database (save the NULL). This can be done, pretty easily.



First, setup any field in the BO to return/save an alternate value on NULL. Because BOs are strongly typed, their properties for the fields in the db can't be null. So, if the field is an integer, you might return a 0 if the field is NULL, or maybe you return Integer.MinValue...the value just needs to be a value that wouldn't be valid for that field. Then, if the property in the BO is set to this value, when it is saved, the BO will actually save a NULL back the db.



Second, setup the TopMostValue of the DropDownList to use the value that is the field's NULL value. I.e. you might set the text to "" and the value to whatever your returning for NULL, like 0. Note that the value is a String, so if you are using a null return value like Integer.MinValue, you probably want to set that in code, otherwise you'll have to type in the actual value.



Once you have these two done, you should see a new value in the drop down list and when you select it, NULL is saved back to the database.



I hope that was helpful. If not, keep asking questions! BigGrin
Vincent C.
Vincent C.
StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)StrataFrame Beginner (2 reputation)
Group: Forum Members
Posts: 2, Visits: 10
Hi, i'm a really Strataframe beginner (in english too) and i learn for 3 weeks on the c-sharps sample (great thanks for that !! )



my first really big problems is to have a form with data bind on a table (name: Championnat), this form contain a dropdownlist bind on a key from a child table (name: TypeChampionnat)

here it is




PopulationType="BusinessObject" Width="175px"

BusinessObjectName="BOChampionnats" BindingField="c_TypeChamp">


displayfieldnamesalternate="Libelle|" dropdownformatstring=""

formatstring="{0}" methodtoexecute="FillTypeChampionnat;" valuemember="Code">






c_TypeChamp: the foreign key

FillTypeChampionnat: the method that fill the list



When i try to add() a new record in the business object it raise an exception



[ArgumentOutOfRangeException: 'lstTypeChampionnat' a un SelectedValue qui n'est pas valide, car il n'existe pas dans la liste des éléments.

Nom du paramètre : value]

System.Web.UI.WebControls.ListControl.set_SelectedValue(String value) +1827626





i know it's "normal" because the field c_TypeChamp is null

i know i can set a default value in the method "_SetDefaultValues()" BUT i don't want to set a default value BigGrin



so what can i do ??



a solution in asp.net forum is to populate manualy the dropdownlist with a default "-1" value with
AppendDataBoundItems="True"


and

ListItem Selected="True" Text="" Value="-1"




but it generate the error

Générer (web): Vous ne pouvez pas utiliser la collection par défaut 'Items' de MicroFour.StrataFrame.UI.Web.DropDownList sans les balises de propriété lorsque vous utilisez une version filtrée de la même collection.




thanks for your help

and thanks to Michel Levy to introduce me to strataframe Tongue
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search