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

[Solved] Multiple Item Radcombobox

1 Answer 117 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
noyan
Top achievements
Rank 1
noyan asked on 09 Jun 2009, 11:25 AM
I got a radcombobox and I use autocomplete features it works for single item well but when I set Autocompleteseperator property it didnt work. radcombobox and the server code which I used for autocomplete features given below all help will be appreciated.

 

<telerik:RadComboBox ID="cmbUnvan" Runat="server" AllowCustomText="True"   
AutoPostBack="True" EnableLoadOnDemand="True"   
onitemsrequested="cmbUnvan_ItemsRequested" Height="73px" Width="230px"   
AutoCompleteSeparator=";" MarkFirstMatch="True">   
<CollapseAnimation Duration="200" Type="OutQuint" />   
</telerik:RadComboBox> 
 
 
protected void cmbUnvan_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)    
{  
 
RadComboBox combo = (RadComboBox)o;   
combo.Items.Clear();  
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Personelcon"].ConnectionString;   
string text = e.Text;   
string sql = "SELECT * from Unvan WHERE Uname LIKE '" + text.Replace("'", "''") + "%'";   
SqlCommand selectCommand = new SqlCommand(sql, connection);   
SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);   
DataTable dt = new DataTable();   
adapter.Fill(dt);  
foreach (DataRow row in dt.Rows)   
{  
RadComboBoxItem item = new RadComboBoxItem(row["Uname"].ToString());   
item.Value = row["Uid"].ToString();   
//item.Text = Convert.ToString(row["Uname"]);   
combo.Items.Add(item);  
}  

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 10 Jun 2009, 06:07 AM
Hello Noyan,

Try modifying the code and see whether it is working fine.

CS:
 
protected void cmbUnvan_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)  
{  
    RadComboBox combo = (RadComboBox)o;  
    if (e.Text.Contains(";"))  
    {              
        String temp = e.Text.ToString();  
        int index = temp.LastIndexOf(";");  
        text = temp.Substring(index + 1);  
    }  
    else  
    {  
        text = e.Text;  
    }  
    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Personelcon"].ConnectionString);  
    string sql = "SELECT * from Unvan WHERE Uname LIKE '" + text.Replace("'""''") + "%'";  
    SqlCommand selectCommand = new SqlCommand(sql, connection);  
    SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);  
    DataTable dt = new DataTable();  
    adapter.Fill(dt);  
    foreach (DataRow row in dt.Rows)  
    {  
        RadComboBoxItem item = new RadComboBoxItem(row["Uname"].ToString());  
        item.Value = row["Uid"].ToString();  
        //item.Text = Convert.ToString(row["Uname"]);     
        combo.Items.Add(item);  
    }  
}  

JavaScript:
 
<script type="text/javascript"
function pageLoad() 
    var combo = $find("<%= cmbUnvan.ClientID %>"); 
    if(combo.get_text() != ""
    { 
        combo.set_text(combo.get_text()+';'); 
    } 
</script> 
Hope this helps :)

Thanks,
Shinu.
Tags
ComboBox
Asked by
noyan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or