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

[Solved] Grid Selected Rows

1 Answer 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Don
Top achievements
Rank 1
Don asked on 21 Apr 2008, 02:03 PM
Hi, Greetings,
I have a web page that lets users select items. To let the user do this, we have two grids, the left grid shows all the available items, and the right side grid shows selected rows. we have two buttons in between one to select and one to remove selected item. (Both the grids have similar columns)
on button click (Server side), we would like to get the left side selected rows (update the database) and then ADD it to the right side selected grid.  (we have problems of adding those selected rows to the other grid)

What is the best way to do this? I have found no simpler way of acheiving this yet. can you please advise...

Thanks Don Almeida.

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 24 Apr 2008, 11:48 AM
Hi Don,

Here is an example how to accomplish this task using RadGrid ajaxified by RadAjax for ASP.NET AJAX:

            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
                <AjaxSettings> 
                    <telerik:AjaxSetting AjaxControlID="Button1">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                            <telerik:AjaxUpdatedControl ControlID="RadGrid2" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                    <telerik:AjaxSetting AjaxControlID="Button2">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                            <telerik:AjaxUpdatedControl ControlID="RadGrid2" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                </AjaxSettings> 
            </telerik:RadAjaxManager> 
            <br /> 
            Select a row and click one of the arrow buttons <br />to transfer it to the opposite table   
            <table> 
                <tr> 
                    <td> 
                        <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource">  
                            <ClientSettings> 
                                <Selecting AllowRowSelect="True"></Selecting> 
                            </ClientSettings> 
                        </telerik:RadGrid> 
                    </td> 
                    <td> 
                        <asp:Button ID="Button1" runat="server" Text=">" OnClick="Button1_Click"></asp:Button> 
                        <br /> 
                        <asp:Button ID="Button2" runat="server" Text="<" OnClick="Button2_Click"></asp:Button> 
                    </td> 
                    <td> 
                        <telerik:RadGrid ID="RadGrid2" runat="server" OnNeedDataSource="RadGrid2_NeedDataSource">  
                            <ClientSettings> 
                                <Selecting AllowRowSelect="True"></Selecting> 
                            </ClientSettings> 
                        </telerik:RadGrid> 
                    </td> 
                </tr> 
            </table> 

    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
    {  
        RadGrid1.DataSource = List1;  
    }  
 
    protected void RadGrid2_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
    {  
        RadGrid2.DataSource = List2;  
    }  
 
    protected void Button1_Click(object sender, System.EventArgs e)  
    {  
        foreach (GridDataItem item in RadGrid1.SelectedItems)  
        {  
            List1.Remove(item["Item"].Text);  
            List2.Add(item["Item"].Text);  
        }  
        RadGrid1.Rebind();  
        RadGrid2.Rebind();  
    }  
 
    protected void Button2_Click(object sender, System.EventArgs e)  
    {  
        foreach (GridDataItem item in RadGrid2.SelectedItems)  
        {  
            List2.Remove(item["Item"].Text);  
            List1.Add(item["Item"].Text);  
        }  
        RadGrid1.Rebind();  
        RadGrid2.Rebind();  
    }  
 
    private ArrayList List1  
    {  
        get 
        {  
            ArrayList obj = (ArrayList)Session["list1"];  
            if (obj == null)  
            {  
                ArrayList list = new ArrayList();  
 
                list.Add("string1");  
                list.Add("string2");  
                list.Add("string3");  
 
                Session["list1"] = list;  
 
                return list;  
            }  
            return obj;  
        }  
    }  
 
    private ArrayList List2  
    {  
        get 
        {  
            ArrayList obj = (ArrayList)Session["list2"];  
            if (obj == null)  
            {  
                ArrayList list = new ArrayList();  
 
                list.Add("string4");  
                list.Add("string5");  
                list.Add("string6");  
 
                Session["list2"] = list;  
 
                return list;  
            }  
            return obj;  
        }  
    } 

Feel free to modify/extend the logic to meet your additional requirements (if present).

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Don
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or