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

autosuggest combox inside radgrid

4 Answers 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dariusz Tomoń
Top achievements
Rank 1
Dariusz Tomoń asked on 14 Aug 2008, 11:14 PM
Hi,

What is the best approach to implement autosuggest combobox inside radgrid. Most examples, including PDF self-peaced file are obsolete and they use external ascx file.
Can you please provide step-by-step instruction how to get combobox inside radgrid during insert/update operation. I would like to have combo which starts to retrieve matching records from database after entering 4-th letter, not earlier to eliminate additional traffic.

Best Regards,

Darek 

4 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 19 Aug 2008, 07:42 AM
Hi Dariusz,

To see more information on the requested functionality, please refer to the following example.
The code uses a load on demand combo. The ItemsRequested handler is used to select new items from the database:

,cs
 private void list_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)  
        {  
            ((RadComboBox)o).DataTextField = this.DataField;  
            ((RadComboBox)o).DataValueField = this.DataField;  
            ((RadComboBox)o).DataSource = GetDataTable("SELECT DISTINCT " + this.UniqueName + " FROM Customers WHERE " + this.UniqueName + " LIKE '" + e.Text + "%'");  
            ((RadComboBox)o).DataBind();  
        } 

You can initially return no records, up until the moment the user enters four symbols.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dariusz Tomoń
Top achievements
Rank 1
answered on 19 Aug 2008, 10:21 AM
Hi,

Thank you for your reply. I know how to populate combobox when it's stand alone. I rather thought about example or snippet of code covering:

1. Where to put combobox in the RadGrid area so that it is shown during insert/edit a record
2. How to reffer to this combo in code to fill in it with items (in what event function)

Best Regards

Dariusz Tomon
0
Princy
Top achievements
Rank 2
answered on 19 Aug 2008, 11:18 AM
Hi Dariusz,

1.You can place the RadComboBox in the EditItemTemplate of a TemplateColumn so that it will appear in Insert/Edit Mode as shown below:
aspx:
<telerik:GridTemplateColumn UniqueName="ComboBox"
        <EditItemTemplate> 
            <telerik:RadComboBox ID="RadComboBox1" runat="server"
            </telerik:RadComboBox> 
        </EditItemTemplate> 
</telerik:GridTemplateColumn> 

2.You can refer to the ComboBox in EditMode as shown below.
cs:
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem item = (GridEditableItem)e.Item; 
            RadComboBox rdcbx = (RadComboBox)item["ComboTemplate"].FindControl("RadComboBox1"); 
            rdcbx.DataSourceID = "SqlDataSource1"
            rdcbx.DataTextField = "DataType"
            rdcbx.DataValueField = "DataType"
        } 
    } 

Thanks
Princy.





0
Dariusz Tomoń
Top achievements
Rank 1
answered on 19 Aug 2008, 10:01 PM
Hi,

Thank you. Can you help me to populate embaded combobox from your example then. I would like to have load on demand combo with function to populate manually.

My population function would be:


protected

void rdcbx_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)

{

if (e.Text.Length < 2)

return;

DataTable dt = FetchMatchingBranze(e.Text);

RadComboBox combo = (RadComboBox)o;

combo.Items.Clear();

foreach (DataRow row in dt.Rows)

{

RadComboBoxItem item = new RadComboBoxItem(row["NAZWA_BRANZA"].ToString().ToLower());

item.Value = row[

"idTB_BRANZA"].ToString();

combo.Items.Add(item);

}

}


// ############## helping procedure

private

DataTable FetchMatchingBranze(string combo_text)

{

SqlConnection cn = new SqlConnection(SqlDataSource1.ConnectionString);

string sqlstring = "select idTB_BRANZA,NAZWA_BRANZA from tb_branza where idTB_JEZYK=1 and NAZWA_BRANZA like '%" + combo_text + "%' order by nazwa_branza";

SqlCommand cm = new SqlCommand(sqlstring, cn);

//string sql = "SELECT * from CountryCodes WHERE Country LIKE '" + partialName.Replace("'", "''") + "%'";

 

SqlDataAdapter adapter = new SqlDataAdapter(cm);

DataTable dt = new DataTable();

adapter.Fill(dt);

cn.Close();

return dt;

}


Ho to fire those populating procedures so that populate my combo, where to fire them from?

Best regards

Darek

Tags
Grid
Asked by
Dariusz Tomoń
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Dariusz Tomoń
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or