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

GridItem Edit and IsInEditMode

1 Answer 569 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tigger Tag
Top achievements
Rank 1
Tigger Tag asked on 17 Oct 2011, 10:38 PM
Hi,

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


 

 

 

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Oct 2011, 05:16 AM
Hello Ana,

When you are making all row editable on initial page-load, is applicable only with in-forms edit mode(EditForms, WebUserControl or FormTemplate custom edit form). Make sure that the edit mode is EditForms and check for the condition as shown below.

C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (!Page.IsPostBack && e.Item is GridEditableItem)
    {
        e.Item.Edit = true;
    }
}
Also check the following help documentation which explains more about this.
Put All Items in Edit Mode.

Thanks,
Shinu.
Tags
Grid
Asked by
Tigger Tag
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or