Cannot get a reference to an edited item

3 posts, 0 answers
  1. Bill
    Bill avatar
    175 posts
    Member since:
    Apr 2010

    Posted 30 Aug 2010 Link to this post

    I have a RadGrid with an Edit button on the left.

    When I click on the Edit button, I simply want to enable/disable some fields.

    No matter what I try in the below code-behind, I'm getting a null value from the "editedItem", which then means the rest of the items using the FindControl will also be null.

    Can someone please inform me how I can get a reference to the edited item (editedItem)?

    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
            {
                if (e.CommandName == "Edit")
                {
                    if (e.Item is GridDataItem)
                    {
                      
                        GridEditableItem editedItem = (source as RadGrid).NamingContainer as GridEditableItem;
                        //GridEditableItem editedItem = e.Item as GridEditableItem;

                        DropDownList FileTypeID = editedItem.FindControl("FileTypeID") as DropDownList;
                        TextBox StartPosition = editedItem.FindControl("StartPosition") as TextBox;
                        TextBox EndPosition = editedItem.FindControl("EndPosition") as TextBox;
                        TextBox Delimiter = editedItem.FindControl("Delimiter") as TextBox;
                        CheckBox IsMultiRecordType = editedItem.FindControl("IsMultiRecordType") as CheckBox;
                        TextBox FirstRecordIndicator = editedItem.FindControl("FirstRecordIndicator") as TextBox;
                        TextBox RecordIndicatorIndex = editedItem.FindControl("RecordIndicatorIndex") as TextBox;

                        if (IsMultiRecordType.Checked == true)
                            FirstRecordIndicator.Enabled = true;
                        else
                        {
                            FirstRecordIndicator.Text = null;
                            FirstRecordIndicator.Enabled = false;
                        }

                        switch (FileTypeID.SelectedItem.Text)
                        {
                            case "Space Fixed Length":
                                StartPosition.Enabled = true;
                                EndPosition.Enabled = true;
                                Delimiter.Text = null;
                                Delimiter.Enabled = false;
                                RecordIndicatorIndex.Text = null;
                                RecordIndicatorIndex.Enabled = false;
                                break;
                            case "Delimited File":
                                StartPosition.Text = null;
                                StartPosition.Enabled = false;
                                EndPosition.Text = null;
                                EndPosition.Enabled = false;
                                Delimiter.Enabled = true;
                                RecordIndicatorIndex.Enabled = true;
                                break;
                            case "HL7":
                                StartPosition.Text = null;
                                StartPosition.Enabled = false;
                                EndPosition.Text = null;
                                EndPosition.Enabled = false;
                                Delimiter.Enabled = true;
                                RecordIndicatorIndex.Enabled = true;
                                break;
                        }
                    }
                }
            }

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 31 Aug 2010 Link to this post

    Hello William,

    If you want to enable/disable controls in edit mode, access that control in ItemDataBound event like below.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
           if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem editedItem = (GridEditableItem)e.Item;
                DropDownList FileTypeID = editedItem.FindControl("FileTypeID") as DropDownList;
                // . . . . .  . . . . .
            }
        }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bill
    Bill avatar
    175 posts
    Member since:
    Apr 2010

    Posted 31 Aug 2010 Link to this post

    Thanks Princy, that worked perfectly:)
Back to Top