RadComboBox SelectedIndexChanged事件在RadGrid中使用就地编辑时不触发
本文关键字:编辑 事件 SelectedIndexChanged RadGrid RadComboBox | 更新日期: 2023-09-27 18:18:37
我在使用类文件构建的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;
}
您需要一个具有CommandName="Select"
集的按钮。没有这个,事件就不会触发。这是问题所在吗?
这个链接给出了更多的细节
编辑:问题可能是下拉列表被动态地添加到网格中,因此每次绑定行时都需要添加事件。根据我的经验,radGrid和GridView在事件模型方面以相同的方式工作,因此这个so答案可能会对您进行排序。祝你好运-我最初的想法是,这是不可能的,但可能有一个前进的道路
问题是我只设置了RadComboBox的Value属性,而没有设置Text属性。即使文本值在编辑模式下显示在RadComboBox中,显然它显示的是value属性。一旦它被设置,它就开始像它应该做的那样发送。
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";