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

Cannot get a reference to an edited item

2 Answers 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 2
Bill asked on 30 Aug 2010, 10:57 PM
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 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 31 Aug 2010, 05:18 AM
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.
0
Bill
Top achievements
Rank 2
answered on 31 Aug 2010, 02:51 PM
Thanks Princy, that worked perfectly:)
Tags
Grid
Asked by
Bill
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Bill
Top achievements
Rank 2
Share this question
or