Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
25
Bind data to combobox from model
posted

Hi,

I have a set of objects in model. I created a combofor control and assigned string property for both ValueKey and TextKey(find an example below). When I am setting a selected value to the model property, it is not displaying anything in the control. But it is working fine, if I am setting ValueKey as integer type. Could you please suggest us some options to achieve this by setting ValueKey and TextKey as string.

<%= Html.Infragistics()

.ComboFor(m => m.ProgramName)

.ID("cmbProgram")

.ValueKey("ProgramName")

.TextKey("ProgramName")

.ItemTemplate("${ProgramName}")  

.DataBind()

.Render() %></td>


 

 

Parents
No Data
Reply
  • 11095
    Offline posted

    Hello Hemalatha,

    ComboFor is used for a model with property that can have different values. In other words if you have the following class with the following properties

    public class User
    {
        public int Id { get; set; }

        public string Username { get; set; }

        public string CountryId { get; set; }
    }

    The ComboFor wrapper can be used to set a Combo for changing the CountryId value (note that country id is not integer but string).

    In order to have values in the dropdown list a collection of countries should be provided to the combo.

    I have created a small sample to demonstrate that.

    Let me know if you need further assistance.

    ComboSample.zip
Children
No Data