ComboBox's SelectedItem in MVC App

  1. #1

    ComboBox's SelectedItem in MVC App

    Okay, I think I'm stuck. I have ComboBox that its initial value is set from the controller but the combo's value always blank.

    Controller :


    Function Form() As ActionResult
    	ViewData("SEX") = "F"
    	Return View()
    End Function
    View :
    <ext:ComboBox runat="server" ID="cbSEX" FieldLabel="SEX">
    	<Items>
    		<ext:ListItem Text ="Male" Value="M" />
    		<ext:ListItem Text ="Female" Value="F" />
    	</Items>
    	<SelectedItem  Value='<%#  ViewData("SEX") %>'  AutoDataBind="true" />
    </ext:ComboBox>
    Anyway, it works fine if I set the selecteditem manually, e.g.
    <SelectedItem  Value="M" />
    Anybody here have any idea?




  2. #2

    RE: ComboBox's SelectedItem in MVC App

    I guess it's bug. My workaround for this issue is to set the combo via javascript or server code (even its MVC app) :p
  3. #3

    RE: ComboBox's SelectedItem in MVC App



    I should probably make this a new question, but...

    How can you set the combobox programmatically in C#? I can't set it using .SelectedItem or .SelectedIndex (as those are both get only), so how can I set it?
  4. #4

    RE: ComboBox's SelectedItem in MVC App

    cbSEX.SelectedItem.Value = "F"
    ' or
    cbSEX.SelectedItem.Text = "Female"
  5. #5

    RE: ComboBox's SelectedItem in MVC App

    Thank you very much! I guess I would expect that to change the value and change the text, but not select the item that has that value or text. That's probably because I'm used to the asp:dropdownlist.

Similar Threads

  1. ComboBox and selectedItem.value
    By cwolcott in forum 1.x Help
    Replies: 3
    Last Post: Feb 01, 2012, 7:48 AM
  2. Replies: 4
    Last Post: Nov 30, 2011, 5:25 AM
  3. combobox.selectedItem
    By gidi in forum 1.x Help
    Replies: 2
    Last Post: Jul 07, 2011, 7:42 PM
  4. ComboBox SelectedItem according to Value problem
    By juredecman in forum 1.x Help
    Replies: 0
    Last Post: Aug 25, 2010, 8:57 PM
  5. Replies: 4
    Last Post: Feb 02, 2010, 4:08 PM

Posting Permissions