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

Duplicate Row Context Menu

1 Answer 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ian Welsh
Top achievements
Rank 1
Ian Welsh asked on 20 May 2010, 10:55 PM
It is possible to have a context menu that will allow you to duplicate information from the row you are selecting the context menu from?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 May 2010, 01:42 PM
Hello Ian Welsh,

I guess you want to implement "duplicate row" option using Contextmenu for grid. If so you can attach ItemClick event to RadContextMenu and retrieve the row values, create new row and then add to DataSet as shown below.

You can use the a HiddenField for getting the index of corresponding griditem on server side as used in the demo.

C#:


 protected
 void RadMenu1_ItemClick(object sender, RadMenuEventArgs e) 
    { 
        int radGridClickedRowIndex; 
        radGridClickedRowIndex = Convert.ToInt32(Request.Form["radGridClickedRowIndex"]); 
        switch (e.Item.Text) 
        { 
            case "Duplicate"
                {                                      
                   GridDataItem item = (GridDataItem)RadGrid1.MasterTableView.Items[radGridClickedRowIndex]; 
                   string str = item["EmployeeID"].Text; 
                   DataSet employeesData = new DataSet(); 
                   SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString); 
                   SqlDataAdapter adapter = new SqlDataAdapter(); 
                   adapter.SelectCommand = new SqlCommand("SELECT [EmployeeID], [FirstName] FROM Employees", con); 
                   adapter.Fill(employeesData, "Emp"); 
                   DataTable dt = employeesData.Tables["Emp"]; 
                   DataRow[] rows = dt.Select("EmployeeID=" + str); 
                   DataRow row = dt.NewRow(); 
                    for (int i = 0; i <= dt.Columns.Count - 1; i++) 
                        { 
                            row[i] = rows[0][i]; 
                        } 
                    dt.Rows.Add(row); 
                    SqlCommandBuilder cmdb = new SqlCommandBuilder(adapter); 
                    adapter.Update(employeesData, "Emp"); 
                    RadGrid1.Rebind(); 
                 } 
                break
         } 
     } 

Regards,
Shinu.
Tags
Grid
Asked by
Ian Welsh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or