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

Add values to datatable in button click

3 Answers 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Venkatesh
Top achievements
Rank 1
Venkatesh asked on 16 Jan 2013, 09:24 AM
Hi,
I have a submit button in my page, in which i am trying to get the values of the grid and add it to datatable.

I have the below code:
protected void Button1_Click(object sender, EventArgs e)
       {
          RadGrid grid = (this.FindControl("RadGrid1") as RadGrid);
           if(grid.MasterTableView.IsItemInserted)
           {
               (grid.MasterTableView.GetItems(GridItemType.CommandItem)[0] as GridCommandItem).FireCommandEvent(RadGrid.PerformInsertCommandName, string.Empty);
           }
           else if(grid.EditItems.Count > 0)
           {
               grid.EditItems[0].FireCommandEvent(RadGrid.UpdateCommandName, string.Empty);
           }
           else
           {
               (grid.MasterTableView.GetItems(GridItemType.Item)[0] as GridDataItem).FireCommandEvent(RadGrid.DeleteCommandName, string.Empty);
           }
       }

How to retrieve the values in Insert/update/delete mode and add it to a datatable ?

Thanks

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Jan 2013, 09:41 AM
Hi,

You can retrieve the new values in UpdateCommand as shown below.
C#:
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem editItem = e.Item as GridEditableItem;
        Hashtable newValues = new Hashtable();
        e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editItem);
        string id = newValues["ID"].ToString();
    }

Thanks,
Shinu
0
Venkatesh
Top achievements
Rank 1
answered on 16 Jan 2013, 10:10 AM
Hi Shinu,

I want to retrieve the values in button and not in the update command. How to do that?

Thanks
0
Shinu
Top achievements
Rank 2
answered on 17 Jan 2013, 09:26 AM
Hi,

Try the following code.
C#:
void edit_Click(object sender, EventArgs e)
{
        foreach (GridEditableItem item in RadGrid2.MasterTableView.GetItems(GridItemType.EditItem))
        {
          TextBox txt = (TextBox)item["Uniquename"].Controls[0];
          string value = txt.Text;
        }
 }

Thanks,
Shinu
Tags
Grid
Asked by
Venkatesh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Venkatesh
Top achievements
Rank 1
Share this question
or