I am using RadGrid and want to make all rows editable on the initial load. I am setting all rows editable as shown below:
protected
void Grid_ItemCreated(object sender, GridItemEventArgs e) {
if (!IsPostBack && e.Item is GridDataItem) {
e.Item.Edit =
true;
}
}
But when ItemDataBound even is fired IsInEditMode property is still set to false. But Edit property is correctly set to true. In the RadGrid documentation says "We suggest using IsInEditMode instead of Edit to check whether an Item is in edit more or not.". But the IsInEditMode property is set to false. Why is IsInEditMode property not set to true? I added my item data bound event handler below.
protected void Grid_ItemDataBound(object sender, GridItemEventArgs e) {
if
(e.Item is GridEditableItem && e.Item.IsInEditMode) {
//--------------------------------------never getting to this block
DropDownList statusDropDown = editedItem.FindControl("StatusDropDown") as DropDownList;
//do something with statusDropDown
}
}
I tried changing my event handle to use Edit property instead, then the code is not finding control in the EditItemTemplate StatusDropDown DropDownList.
Here is my modified code and grid decleration:
protected void Grid_ItemDataBound(object sender, GridItemEventArgs e) {
if
(e.Item is GridEditableItem && e.Item.Edit) {
//------------------------------------------------I am geting null for statusDropDown
DropDownList statusDropDown= editedItem.FindControl("StatusDropDown") as DropDownList;
//do something with statusDropDown
}
}
<telerik:RadGrid ID="Grid" runat="server" GridLines="None" AutoGenerateColumns="false"
OnItemDataBound="Grid_ItemDataBound" OnNeedDataSource="Grid_NeedDataSource"
OnItemCreated="Grid_ItemCreated" AllowMultiRowEdit="true">
<MasterTableView DataKeyNames="ClassId" EditMode="InPlace">
<Columns>
<telerik:GridBoundColumn UniqueName="ClassName" HeaderText="Class Name" DataField="ClassId"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Site" DataField="SiteId" ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName="Status" HeaderText="Status">
<ItemTemplate>
<asp:Label ID="statusLabel" runat="server">
<%# DataBinder.Eval(Container.DataItem, "StatusId")%>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="StatusDropDown" runat="server" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
I am trying to avoid using prerenderer becasue of rebind call.
Anyone has any idea what I am missing. Please let me know if you see a better way to do this. I appreciate any help.
Thanks,
Ana