Setting Default Value to Rad ComboBox with EnableLoadOnDemand="true"

6 posts, 1 answers
  1. Rajiv Prashant
    Rajiv Prashant avatar
    16 posts
    Member since:
    Oct 2009

    Posted 14 Dec 2010 Link to this post

    Hi,
     I am using RadCombobox with EnableLoadOnDemand="true" Option , its working fine.I have Clear Button in the same page ,After clicking on Clear Button i need to display default item in combobox.

    I saw solution for the same requirement , but thats not working .

    Following is Aspx Code :
        

    <telerik:RadComboBox ID="RadComboBox1" runat="server"
        EmptyMessage="Select" EnableLoadOnDemand="true"
         >
    </telerik:RadComboBox>

    <asp:Button ID="btnSubmit" runat ="server" Text ="Clear" OnClick ="btnSubmit_click"/>

    Following is Csharp Code :

        

    protected void Page_Load(object sender, EventArgs e)
        {
          

              if (!IsPostBack)
                {
                    DataTable dataTable = CreateDataSource();

                    foreach (DataRow dataRow in dataTable.Rows)
                    {
                        RadComboBoxItem item = new RadComboBoxItem();
                        item.Text = (string)dataRow["Name"];
                        item.Value = dataRow["ID"].ToString();
                        RadComboBox1.Items.Add(item);
                        item.DataBind();
                    }
                    // preselect the second item
                    //RadComboBox1.SelectedValue = "0";
                    RadComboBox1.Items[0].Selected = true;

                }

         

        }
       
       

        protected DataTable CreateDataSource()
        {
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add(new DataColumn("ID", typeof(string)));
            dataTable.Columns.Add(new DataColumn("Name", typeof(string)));

            DataRow dr = dataTable.NewRow();
            dr["ID"] = "0";
            dr["Name"] = "SELECT NAME";
            dataTable.Rows.Add(dr);

            DataRow dr1 = dataTable.NewRow();
            dr1["ID"] = "1";
            dr1["Name"] = "Name1";
            dataTable.Rows.Add(dr1);

            DataRow dr2 = dataTable.NewRow();
            dr2["ID"] = "2";
            dr2["Name"] = "Name2";
            dataTable.Rows.Add(dr2);

            DataRow dr3 = dataTable.NewRow();
            dr3["ID"] = "3";
            dr3["Name"] = "Name3";
            dataTable.Rows.Add(dr3);

            return dataTable;

        }

        protected void btnSubmit_click(object sender, EventArgs e)
         {
             RadComboBox1.Items[0].Selected = true;
        }

    }


    Thanks,

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Dec 2010 Link to this post

    Hello Rajiv,

    Based on your code and logic, I presume that the selecteditem text is not showing even if the item is selected. Have you tried setting the Text explicitly to overcome this?

    Give a try with the following code and let me know if you need further assistance.

    C#:
    protected void btnSubmit_click(object sender, EventArgs e)
      {
          RadComboBox2.Items[0].Selected = true;
          RadComboBox2.Text = RadComboBox2.Items[0].Text; 
      }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rajiv Prashant
    Rajiv Prashant avatar
    16 posts
    Member since:
    Oct 2009

    Posted 15 Dec 2010 Link to this post

    Thanks, Its works.
  5. Marcel
    Marcel avatar
    2 posts
    Member since:
    Jun 2014

    Posted 04 Jun 2014 Link to this post

    Hi there guys, i have a question 

    i have a Telerik:RadCombobox but i am having some difficulty trying to do something which i am to believe is rather simple, let me paste some code for you

    <telerik:RadComboBox ID="CPPActionRadCombo" runat="server" EmptyMessage="Select Action" Skin="Outlook">                                                                                                                                                                                      <Items>                                                                      <telerik:RadComboBoxItem Text="Append" Value="1" runat="server" />          <telerik:RadComboBoxItem Text="Override" Value="2" runat="server" />                              </Items>                                                                         </telerik:RadComboBox>


    ok so not that its not working, it does, the thing is when i look at this combobox, i have 3 values 
    Select Action
    Append
    Override

    So when the page loads i want the user to see "Select Action" as a default
    so when he clicks on the combobox he can choose Append or override, i do not want the user to be able to select the option "Select Action" or see it as an item, i just want that as an indicator in the combobox to say that here they must select an action, once they have selected an action i don't want them to be able to select "Select Action" 

    so put easy for you 
    there should only be 2 values that can be selected, but when the page loads i want the combobox to show me "Select Action" but in reality it must not be select-able 

    Please Help, Please please 
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Jun 2014 in reply to Marcel Link to this post

    Hi Marcel,

    The default behavior of RadComboBox is that it will not allow to select the EmptyMeaasge. In your scenario you have set 'Select Action' as the EmptyMeassage so it will not be available in the dropdownlist and the 'Select Action' will show only at first time.
    Please elaborate your requirement if it doesn't help.

    Thanks,
    Shinu.
  7. Marcel
    Marcel avatar
    2 posts
    Member since:
    Jun 2014

    Posted 06 Jun 2014 in reply to Shinu Link to this post

    Hi, i actually figured it out, it ended up looking like this
    <telerik:RadComboBox ID="ActionRadCombo" TabIndex="20" runat="server" Text="Select Action" EmptyMessage="Select Action" Skin="Outlook">
    <Items>
    <telerik:RadComboBoxItem Visible="False" Text="" Value="-1" IsSelected="true" runat="server" />
    <telerik:RadComboBoxItem Text="Append" Value="1" runat="server" />
    <telerik:RadComboBoxItem Text="Override" Value="2" runat="server" />
    </Items>
    </telerik:RadComboBox>
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017