RadControls for ASP.NET AJAX If you need to put grid items in edit mode without additionally rebinding the grid you may use EditIndexes collection before grid is bound. Later, when the grid is bound it will take into account the entries in this collection and will create them in edit mode.
CopyC#
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < RadGrid1.PageSize; i++)
{
RadGrid1.EditIndexes.Add(i);
}
}
CopyVB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim i As Integer
For i = 0 To RadGrid1.PageSize - 1
RadGrid1.EditIndexes.Add(i)
Next i
End Sub
There are cases in which you may want to force the grid items in edit mode when the grid displays initially on the page.This is a straightforward task. You simply need to attach to the PreRender event of the control, traverse the items in the grid, detect those which are editable and set their Edit property to true. After traversing all items and performing this operation, you have to rebind the grid (calling explicitly its Rebind() method) to reflect the changes.
In the code-behind:
CopyC#
private void RadGrid1_PreRender(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
foreach (GridItem item in RadGrid1.MasterTableView.Items)
{
if (item is GridEditableItem)
{
GridEditableItem editableItem = item as GridDataItem;
editableItem.Edit = true;
}
}
RadGrid1.Rebind();
}
}
CopyVB.NET
Private Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender
If Not IsPostBack Then
For Each item As GridItem In RadGrid1.MasterTableView.Items
If TypeOf item Is GridEditableItem Then
Dim editableItem As GridEditableItem = CType(item, GridDataItem)
editableItem.Edit = True
End If
Next
RadGrid1.Rebind()
End If
End Sub
Another option (which is applicable only with in-forms edit mode (EditForms, WebUserControl or FormTemplate custom edit form) is to set the Edit property of all grid rows to true on initial load hooking the ItemCreated event:
CopyVB.NET
Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
If (Not Page.IsPostBack AndAlso TypeOf e.Item Is GridEditableItem) Then
e.Item.Edit = True
End If
End Sub
CopyC#
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (!Page.IsPostBack && e.Item is GridEditableItem)
{
e.Item.Edit = true;
}
}Thus you will avoid the grid rebinding on PreRender.