Question

I am using inplace editing on a RadGrid that is built using a class file. Everything is working well except I am having an issue the SelectedIndexChanged event not firing when the grid is in edit mode. Any thoughts?

private void RadGrid_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        try
        {
            if ((e.Item as GridDataItem) == null) { return; }
            ((RadNumericTextBox) (e.Item as GridDataItem)["Percentage"].Controls[0]).Width = Unit.Pixel(75);
            ((TextBox) (e.Item as GridDataItem)["Code"].Controls[0]).Width = Unit.Pixel(75);

            RadComboBox _participantList = (e.Item as GridEditableItem)["ID"].Controls[0] as RadComboBox;
            if (null == _participantList) { return; }

            _participantList.Width = Unit.Pixel(120);
            _participantList.DataValueField = "ID";
            _participantList.DataTextField = "ID";
            _participantList.AutoPostBack = true;
            _participantList.DataSource = MAASBaseInterface.ParticipantAPI.GetParticipants();
            _participantList.DataBind();
            _participantList.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(_participantList_SelectedIndexChanged);

            if (!(e.Item.DataItem is GridInsertionObject))
                _participantList.SelectedValue = ((Participant) (e.Item.DataItem)).ID.ToString();
            if (e.Item.DataItem is GridInsertionObject)
                _participantList.EmptyMessage = "-- Select --";
        }
        catch (Exception ex)
        {

            string _ex = ex.Message;
        }
    }
} 

void _participantList_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    //first reference the edited grid item through the NamingContainer attribute
    GridEditableItem editedItem = (sender as RadComboBox).NamingContainer as GridEditableItem;
    int _selectedValue = Convert.ToInt32((editedItem["ID"].Controls[0] as RadComboBox).SelectedValue);
    ParticipantList _participants = MAASBaseInterface.ParticipantAPI.GetParticipants();
    Participant _participant = _participants.Where(a => a.ID == _selectedValue) as Participant;
    RadTextBox _code = editedItem["Code"].Controls[0] as RadTextBox;
    _code.ReadOnly = false;
    _code.Text = _participant.Code;
}
Was it helpful?

Solution 2

The problem was that I was only setting the Value property of the RadComboBox and not the Text property. Even though text value was showing in the RadComboBox in edit mode apparently it was displaying the Value property. As soon as it was set it started posting back just like it was supposed to do.

                if (!(e.Item.DataItem is GridInsertionObject))
                {
                    _participantList.SelectedValue =
                        ((ReinsuranceAgreementParticipant) (e.Item.DataItem)).LegacyReinsurerID.ToString();
                    // I added this line
                    _participantList.Text = ((ReinsuranceAgreementParticipant)(e.Item.DataItem)).LegacyReinsurerID.ToString();
                }
                if (e.Item.DataItem is GridInsertionObject)
                    _participantList.EmptyMessage = "Select Reinsurer";

OTHER TIPS

You need a button that has the CommandName="Select" set. Without that the event doesn't trigger. Could that be the problem?

This link gives more detail

EDIT:

The problem might be that the dropdown list is dynamically added to the grid so that the event needs to be added each time the row is bound. In my experience the radGrid and the GridView works in the same way with respect to the event model so this SO answer might sort you out. Good luck - my initial thoughs were that this couldn't be don't but there may be a way forward

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top