Bind null data in DropDownList


Author
Message
Vincent C.
Vincent C.
StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 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
Reply
Vincent C.
Vincent C.
StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 reputation)StrataFrame Beginner (6 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



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