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

edit in radgrid

1 Answer 39 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dhamodharan
Top achievements
Rank 1
Dhamodharan asked on 25 Oct 2010, 03:57 PM
Hi,

i created radgrid with edit option. when clicked edit button displayed values in textbox. then i clicked enter button means another add new record option has been displayed. how to avoid this problem?

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 26 Oct 2010, 08:08 AM
Hello Dhamodharan,

You can avoid this problem by adding "onkeydown" event to the TextBox and return false(which will not open insert form) if enter key is pressed. Sample code is given below.

ASPX:
<telerik:RadGrid ID="RadGrid2" GridLines="None" runat="server"
      OnItemDataBound="RadGrid2_ItemDataBound">
   <MasterTableView CommandItemDisplay="Top" EditMode="EditForms">
      <Columns>
        <telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" UniqueName="EmployeeID">
        </telerik:GridBoundColumn>
        <telerik:GridEditCommandColumn>
        </telerik:GridEditCommandColumn>
      </Columns>
   </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
       {
           GridEditFormItem gridEditFormItem = e.Item as GridEditFormItem;
           TextBox txtid = (TextBox)gridEditFormItem["EmployeeID"].Controls[0];
           txtid.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13))  {return false};} ");
       }
   }

Thanks,
Princy.
Tags
Grid
Asked by
Dhamodharan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or