RadControls for ASP.NET AJAX
To display the grid column editors inline when the grid switches into edit mode, change the table view's EditMode property to "InPlace".
CopyASPX
<telerik:RadGrid
ID="RadGrid1" runat="server"
DataSourceID="SqlDataSource1"
GridLines="None">
<MasterTableView
EditMode="InPlace"
DataSourceID="SqlDataSource1">
<Columns>
<telerik:GridEditCommandColumn />
</Columns>
</MasterTableView>
</telerik:RadGrid> Note |
|---|
To limit the number of characters the user can enter in the text box editor of the inline editor, set the MaxLength property of the column.
|
Relations between the edited item and the item in regular mode
When InPlace editing is applied, the grid row is of type GridDataItem in regular mode and GridEditableItem in edit regime. Hence you can cast the item in the ItemCreated event (for example) to those types according to its current mode:
CopyC#
private void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
}
else if (e.Item is GridDataItem)
{
GridDataItem dataItem = e.Item as GridDataItem;
}
}
CopyVB.NET
Private Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
ElseIf (TypeOf e.Item Is GridDataItem) Then
Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
End If
End Sub
For information about how to reference controls inside grid rows and edit forms, see Referencing controls in grid row/edit form.
Detecting edit/insert mode with in-place editing
To determine whether edit or insert operation is in progress inside the ItemCreated/ItemDataBound handler of the grid (when having inplace editing), check whether the e.Item instance inside the handler is of type GridEditableItem or GridDataInsertItem respectively. Here are some code snippets which illustrate the approach in question:
CopyC#
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if ((e.Item is GridDataInsertItem) && e.Item.IsInEditMode)
{
}
else if ((e.Item is GridEditableItem) && e.Item.IsInEditMode)
{
}
}
CopyVB.NET
Private Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
If (TypeOf e.Item Is GridDataInsertItem AndAlso e.Item.IsInEditMode) Then
ElseIf (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
End If
End Sub