我在使用类文件构建的 RadGrid 上使用就地编辑。一切都运行良好,除了我遇到问题,当网格处于编辑模式时 SelectedIndexChanged 事件未触发。有什么想法吗?
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;
}