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

[Solved] combo select

5 Answers 158 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
sathies
Top achievements
Rank 1
sathies asked on 15 Oct 2009, 11:00 AM
Hi,
 I have created combox  as below.
 <div> 
    <asp:scriptmanager ID="Scriptmanager1" runat="server"></asp:scriptmanager> 
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
        </telerik:RadAjaxManager> 
        <div id="s" runat="server">  
            <telerik:RadComboBox ID="RadComboBox4" EnableViewState="false" EnableItemCaching="true"   
            EnableLoadOnDemand="true" runat="server"   
            onitemsrequested="RadComboBox4_ItemsRequested">  
            </telerik:RadComboBox> 
               </div> 
               <asp:Button ID="Button1" runat="server" Text="Ajax" onclick="Button1_Click" /> 
         <asp:SqlDataSource ID="SqlDataSource1"   
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
            ProviderName="System.Data.SqlClient" 
            SelectCommand="SELECT * FROM Customers" runat="server"></asp:SqlDataSource> 
          
    </div> 

 protected void Page_Load(object sender, EventArgs e)  
    {  
        RadAjaxManager1.AjaxSettings.AddAjaxSetting(Button1, s, null);  
    }  
 
    protected void RadComboBox4_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)  
    {  
 
        RadComboBox4.DataSourceID = "SqlDataSource1";  
        string selectCommand = "SELECT * FROM CUSTOMERS WHERE CompanyName LIKE '" +  
        e.Text + "%'";  
        SqlDataSource1.SelectCommand = selectCommand;  
        RadComboBox4.DataTextField = "CompanyName";  
        RadComboBox4.DataValueField="CustomerID";  
        RadComboBox4.DataBind();  
    }  
 
 protected void Button1_Click(object sender, EventArgs e)  
    {  
       RadComboBox4.Text = RadComboBox4.EmptyMessage;  
        
          
    } 

I am unable to select the same value from the combo box which I have selected previously.

Scenario: First I have selected a value from the combobox and then  I clicked the button (ajax implemented) which will empty the combobox. Again I want to select the same value from the combobox but unfortunately I am not able to select it. Is there is a problem in my code.

Am using telerik version:2009.2.701.35. Please help me at the earliest

Regards,
Sathies

5 Answers, 1 is accepted

Sort by
0
sathies
Top achievements
Rank 1
answered on 23 Oct 2009, 11:22 AM
Hi,
    Please any one provide me the solution. its very  urgent....

regards
sathies
0
Schlurk
Top achievements
Rank 2
answered on 23 Oct 2009, 10:21 PM
You should probably use ViewState to save the item:
 
ViewState["selectedItem"] = RadComboBox4.SelectedValue; 

And then to get the item back:
 
RadComboBoxItem myItem = ViewState["selectedItem"]; 

0
sathies
Top achievements
Rank 1
answered on 27 Oct 2009, 11:40 AM
Hi Schlurk ,
                sorry for the late reply...
                My problem is; previously selected data is not displayed in the combo box.

                see the visual in the attached file
                step1: first i select a value (Bon app') from the combo and clicked the ajax button the combo gets clear
                step2: once again i tried to select  the same value (Bon app'), but the value is not displayed in combo as in step3

regards
sathies
0
Schlurk
Top achievements
Rank 2
answered on 27 Oct 2009, 09:16 PM
I would suggest taking a deeper look into this ComboBox Demo, since it has the logic you are looking for and there are a few variations between its logic and what you are doing (specifically around databinding).
0
sathies
Top achievements
Rank 1
answered on 30 Oct 2009, 10:03 AM
Hi Schlurk ,
             Thanks for the link, Its works now.

            I change the button clickevent as below (added ClearSection method)

protected void Button1_Click(object sender, EventArgs e)  
    {  
       RadComboBox4.Text = RadComboBox4.EmptyMessage;  
         RadComboBox4.ClearSelection();
      
    } 

regards
sathies

    
Tags
ComboBox
Asked by
sathies
Top achievements
Rank 1
Answers by
sathies
Top achievements
Rank 1
Schlurk
Top achievements
Rank 2
Share this question
or