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

Edit RadGrid Rows

3 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vvamc
Top achievements
Rank 1
Vvamc asked on 21 Feb 2014, 09:32 PM
Hi ,

I Have a  radgrid and i enter the data into the grid from textboxes .I have two fields one is the name and Description fields with an unique id autogenerated in the database. I want to edit the rows on double click of that particular row in the radgrid and  show an updatebutton and cancel button shown in another column and update button  code in the code behind? Help Me out


Thanks in advance

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 24 Feb 2014, 05:26 AM
Hi,

Please try the following sample code snippet to edit row on DoubleClick.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowEdit="true" OnItemCommand="RadGrid1_ItemCommand" AllowPaging="true" OnUpdateCommand="RadGrid1_UpdateCommand">
    <MasterTableView EditMode="InPlace" DataKeyNames="ID">
        <Columns>
            <telerik:GridBoundColumn DataField="Name">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Description">
            </telerik:GridBoundColumn>
            <telerik:GridEditCommandColumn>
            </telerik:GridEditCommandColumn>
        </Columns>
   </MasterTableView>
    <ClientSettings>
        <ClientEvents OnRowDblClick="OnRowDblClick" />
    </ClientSettings>
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
  if (e.CommandName == "EditR")
  {
      GridDataItem item = RadGrid1.Items[e.CommandArgument.ToString()];
      item.Edit = true;
      RadGrid1.Rebind();
  }
}
 
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
  GridEditableItem edit = (GridEditableItem)e.Item;
  string id = edit.GetDataKeyValue("ID").ToString(); //access datakey value
  //access bound columns
  string id = (edit["OrderID"].Controls[0] as TextBox).Text;
  string eid = (edit["EmployeeID"].Controls[0] as TextBox).Text;
  //code to update to db
}

JS:
<script type="text/javascript">
 function OnRowDblClick(sender, eventArgs) {
   var grid = $find("<%=RadGrid1.ClientID %>");
   var master = grid.get_masterTableView();
   editedRow = eventArgs.get_itemIndexHierarchical();
   master.fireCommand("EditR", editedRow);
    }
</script>

Thanks,
Princy
0
Vvamc
Top achievements
Rank 1
answered on 24 Feb 2014, 02:38 PM
Hi Princy,

Thanks and It worked .Can you  help me out if ipress the cancel button the radgrid dissappers and if i press the edit button  the grid dissappers

Thanks
0
Vvamc
Top achievements
Rank 1
answered on 24 Feb 2014, 02:56 PM
Got it Princy.Thanks a lot and it worked. Even the update and cancel worked.
Tags
Grid
Asked by
Vvamc
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Vvamc
Top achievements
Rank 1
Share this question
or