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

Insert selected rows in grid with usercontrol

1 Answer 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Johan
Top achievements
Rank 1
Johan asked on 10 Dec 2008, 12:07 PM

Hi all

I'm trying to make a orderlist grid that have a nested grid for orderitems. It works great and I can change orderitems and delete them.

But I have a problem when I try to insert new orderitems (products) when I use a usercontrol that has its own radgrid with products. The usercontrol works when it's not in the above radgrid. In my usercontrol i search for all products and show the result in a radgrid and then I want to select the product i want to add. But when i use this usercontrol in the orderitemradgrid, it never triggers the search button.
It just add a empty row.

You maybe can’t have a grid with search result to select in an “usercontrol” when you want to insert item? I can’t find any example to show how I should do this.

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 15 Dec 2008, 05:12 PM
Hi Johan,

In order to achieve search/filter option for the populated data in the grid placed in the user control, you can built your filter expression at runtime. For example, you can put a RadComboBox which will give the end users ability to choose column by which the data will be filtered and a textbox containing the comparison data. Here is a code-snippet:

protected void txtSearch_TextChanged(object sender, EventArgs e) 
    { 
        TextBox txt = (TextBox)sender as TextBox; 
        RadComboBox list = (RadComboBox)((txt.NamingContainer).FindControl("rcbFieldName")); 
 
        string option; 
        if (list.SelectedValue == "Freight" || list.SelectedValue == "OrderDate"
        { 
            option = " = "
        } 
        else 
        { 
            option = " LIKE "
        } 
 
        string filterExpression; 
 
        if (option == " = "
        { 
            filterExpression = "(" + list.SelectedValue + option + txt.Text + ")"
        } 
        else 
        { 
            filterExpression = "(" + list.SelectedValue + option + "'%" + txt.Text + "%'" + ")"
        } 
 
        RadGrid1.MasterTableView.FilterExpression = filterExpression; 
    } 
You can refer to this online demo for further reference.

Inside the OnClick server handler after the user clicked the search button, you have to rebind the grid to reflect the changes.

To insert the selected row, you have to raise the OnInsertCommand event of the main grid. There you can get inserted item and find the nested grid in this item in order to pull out the selected item. When you have the selected row there should be no problem to add this row to the order list and to rebind the corresponding detail table. Here is a code snippet:

protected void rgTestWithDifferentBindWay_InsertCommand(object source, GridCommandEventArgs e) 
    { 
        GridEditableItem editedItem = e.Item as GridEditableItem; 
        UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); 
        var selectedValue = ((RadGrid)userControl.FindControl("RadGrid1")).SelectedValue; 
        //from here you can add selected row to the order details table and to rebind details table. 
 
................ 
 

Best regards,
Georgi Krustev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Johan
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or