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

RadComboBox SelectedIndexChanged event not firing when using inplace editing in a RadGrid

6 Answers 447 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 2
Tim asked on 21 Dec 2011, 11:09 PM
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?

Column Definition:
GridDropDownColumn _ID = new GridDropDownColumn
                         {
                             DataField = "ID",
                             HeaderText = "ID",
                             UniqueName = "ID",
                             ListTextField = "ID",
                             ListValueField = "ID",
                             ListDataMember = "ID",
                             DropDownControlType = GridDropDownColumnControlType.RadComboBox,
                             HeaderStyle = { Width = Unit.Pixel(140) },
                             ItemStyle = { Width = Unit.Pixel(140) },
                             ReadOnly = false,
                             Display = true,
                         };
_reinsurerRadGrid.MasterTableView.Columns.Add(_ID);

UserControl Code:
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;
}

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Dec 2011, 04:55 AM
Hello Tim,

Try setting AutoPostBack as true  for DropDown.

-Shinu.
0
Tim
Top achievements
Rank 2
answered on 22 Dec 2011, 03:50 PM
Hi Shinu, if you will look closer at the code you will see this line _participantList.AutoPostBack = true;
0
Tim
Top achievements
Rank 2
answered on 22 Dec 2011, 04:59 PM
I figured it out with the help of this post. 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.

RadGrid_ItemCreated Method code change
if (!(e.Item.DataItem is GridInsertionObject))
{
    _participantList.SelectedValue =
        ((Participant) (e.Item.DataItem)).ID.ToString();
    // I added this line
    _participantList.Text = ((Participant)(e.Item.DataItem)).ID.ToString();
}
if (e.Item.DataItem is GridInsertionObject)
    _participantList.EmptyMessage = "-- Select --";







0
Sandy
Top achievements
Rank 1
answered on 05 Mar 2012, 09:34 PM
Hi
I am using the Rad ComboBox.The Selected index changed event is triggering when I select single index.if I select Multiple indexes the selected index changed property is not firing.Could you guys please help me on this.
Thank you,
0
Princy
Top achievements
Rank 2
answered on 07 Mar 2012, 12:07 PM
Hello,

I tried to reproduce the problem, but no avail. Here is the sample code that i tried which worked for me.
ASPX:
<telerik:RadComboBox ID="radcombobox1" runat="server" AutoPostBack="true" AllowCustomText="true" MarkFirstMatch="true"  AutoCompleteSeparator="," onselectedindexchanged="radcombobox1_SelectedIndexChanged"  >
 <Items>
  <telerik:RadComboBoxItem Text=" item1" Value="" />
  <telerik:RadComboBoxItem Text="item2" Value="" />
  <telerik:RadComboBoxItem Text="item3" Value="" />
  <telerik:RadComboBoxItem Text="item4" Value="" />
  <telerik:RadComboBoxItem Text="item5" Value="" />
  <telerik:RadComboBoxItem Text="item6" Value="" />
  <telerik:RadComboBoxItem Text="item7" Value="" />
 </Items>
</telerik:RadComboBox>
Also take a look into the following documentation.
Autocomplete

Thanks,
Princy.
0
Jaspal
Top achievements
Rank 1
answered on 28 May 2015, 11:59 AM

aspx

 

<telerik:RadComboBox ID="ddldropdwon" runat="server" Width="35px" ViewStateMode="Inherit" AutoPostBack="false" RenderMode="Lightweight" HighlightTemplatedItems="true" OnSelectedIndexChanged="ddldropdwon_SelectedIndexChanged">
</telerik:RadComboBox>

 

 C#

public void ddldropdwon_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            RadComboBox combo = sender as RadComboBox;
            GridDataItem item = (GridDataItem)combo.NamingContainer;
            int index = item.ItemIndex;
            //((CheckBox)gvDetail.Items[index].FindControl("ChkChecked")).Checked = true;

        }

Tags
Grid
Asked by
Tim
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Tim
Top achievements
Rank 2
Sandy
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Jaspal
Top achievements
Rank 1
Share this question
or