This is a migrated thread and some comments may be shown as answers.

GridForeignKey ComboBox Initial Value is 0 ?

3 Answers 323 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 14 Feb 2013, 03:29 PM
Subject says it all. In my GridForeignKey.cshtml I've placed a combo box rather than the dropdownlist. For editing values in my grid it works fantastically. When adding a new row inline however, the default value displayed is 0. This is a non-nullable field with no default. How can I get my own "Select..." text in there initially or nothing at all?

Thank you!
Michael

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 18 Feb 2013, 07:18 AM
Hello Michael,

Basically the easiest way to achieve this will be to use the edit event of the Grid.

I tried other approaches however since most probably the column field is of type int (or nullable int) you wont be able to set the default value to be empty string - which is actually the value of the combo when there is "option label". Also if you want this field to be required you will once again need to make the default value empty string.

For simplicity I created a sample project which you can try. 


Kind regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Robert
Top achievements
Rank 1
answered on 27 Mar 2013, 09:41 PM
Hey Peter,
If I wanted to use a combobox with an Ajax datasource instead of the SelectList for the Foreign key column, what would the razor markup look like for the columns configuration?

Thanks,
Rob
0
Petur Subev
Telerik team
answered on 29 Mar 2013, 07:20 AM
Hello Michael,

I am afraid this is not possible. 
Basically here is the scenario:
ForeignKey column is nothing more than a template column and the template should have the Key/Value pairs to display the text for a given id. However the ComboBox is loaded when the column is being edit - so you cannot use the data it loads in the client template.


Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
ComboBox
Asked by
Michael
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Robert
Top achievements
Rank 1
Share this question
or