How do I set the selected index of an ext:combobox from the serverside?

  1. #1

    How do I set the selected index of an ext:combobox from the serverside?

    How do I set the selected index of an ext:combobox from the serverside?

    I have a sqldatasource with two fields in it. I can see the SelectedItem.Value (display list of the combobox) but I cannot get to the value field. Also when I try to use the SelectedIndex I get the array of the list of items.

    I need to match the value field of the combobox to the value I have stored in my database (like an asp:dropdownlist works).

    James
  2. #2

    RE: How do I set the selected index of an ext:combobox from the serverside?

    Hi,

    use combobox.SelectedItem.Value.ToString().
  3. #3

    RE: How do I set the selected index of an ext:combobox from the serverside?

    Sadeque,

    That's not what I am looking for.

    When I build the combobox on the page from a previous post I need to have the value from my data bind to the selected index or value in the combobox. Currently the stored value is placed in the textfield of the combobox but the selected value is not bound in the drop-down. If the form is re-posted I get the value from the box and a selected index of -1 because the combobox is never bound. See the illustration (combobox.png).



    James
  4. #4

    RE: How do I set the selected index of an ext:combobox from the serverside?

    Hi,

    Can you show the sample which reproduces the problem?
    Here is my test case which works fine
    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
            
        protected void Page_Load(object sender, EventArgs e)
        {
            List<object> lst = new List<object>();
            
            lst.Add(new { Id = 1, Name = "Company A" });
            lst.Add(new { Id = 2, Name = "Company B" });
            lst.Add(new { Id = 3, Name = "Company C" });
            lst.Add(new { Id = 4, Name = "Company D" });
            lst.Add(new { Id = 5, Name = "Company E" });
    
            Store1.DataSource = lst;
            Store1.DataBind();
        }
    
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Test</title>
    </head>
    <body>
        <form id="form1" runat="server">
        
            <ext:ScriptManager ID="sm1" runat="server" />
            
            <ext:Store ID="Store1" runat="server">
                <Reader>
                    <ext:ArrayReader ReaderID="Id">
                        <Fields>
                            <ext:RecordField Name="Id"    Mapping="Id" Type="Int"    />
                            <ext:RecordField Name="Name"  Mapping="Name" Type="String" />
                        </Fields>
                    </ext:ArrayReader>
                </Reader>
            </ext:Store>
            
            <ext:ComboBox runat="server" StoreID="Store1" DisplayField="Name" ValueField="Id">
                <SelectedItem Value="3" />
            </ext:ComboBox>
        </form>
    </body>
    </html>
  5. #5

    RE: How do I set the selected index of an ext:combobox from the serverside?

    vladach,

    <td colspan="2">
      <p>Counselor:* 
        <ext:Store ID="stCounselor" runat="server" AutoLoad="true" DataSourceID="dsCounselorList">
          <Reader>
            <ext:JsonReader ReaderID="UserName">
              <Fields>
                <ext:RecordField Name="UserName" Mapping="UserName" Type="string" />
                <ext:RecordField Name="Counselor" Mapping="Counselor" Type="String" />
              </Fields>
            </ext:JsonReader>
          </Reader>
        </ext:Store>
        
          <ext:ComboBox 
            ID="cboCounselor" runat="server" 
            StoreID="stCounselor" 
            ValueField="UserName" 
            DisplayField="Counselor" 
            LoadingText="Loading..." 
            Editable="false" 
            AllowBlank="false" 
            EmptyText="---- Select Counselor -----"
            Mode="local" 
            TriggerAction="All" 
            Width="250px" 
            ForceSelection="true">
          </ext:ComboBox>
        
    
      </p>
    </td>
    //Server Side
    //Comment: In the OnLoad Event
    
    
    
    
    if (dv[0]["CounselorID"].ToString() != "")
    {
      cboCounselor.SelectedItem.Value = dv[0]["CounselorName"].ToString();
    }
    Correct Counselor's name is in the box but not selected in the list.

    James
  6. #6

    RE: How do I set the selected index of an ext:combobox from the serverside?

    Hi,

    SelectedItem.Value should contains ValueField but you set DisplayField
    Try to use
    cboCounselor.SelectedItem.Value = dv[0]["UserName"].ToString();
  7. #7

    RE: How do I set the selected index of an ext:combobox from the serverside?

    That was it.

    Thanks,

    James

Similar Threads

  1. How to get Index of selected row?
    By huzzy143 in forum 1.x Help
    Replies: 7
    Last Post: Sep 26, 2014, 9:24 PM
  2. how get selected index value of radiogroup
    By abhi_sheklohiya in forum 1.x Help
    Replies: 3
    Last Post: Mar 29, 2012, 10:12 PM
  3. Replies: 0
    Last Post: May 22, 2009, 7:59 AM
  4. [CLOSED] selected index
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 29, 2009, 7:46 AM
  5. ComboBox selected index on button click event.
    By jmilton in forum 1.x Help
    Replies: 9
    Last Post: Mar 25, 2009, 7:06 PM

Posting Permissions