【发布时间】:2016-10-11 07:42:31
【问题描述】:
我有一个Telerik RadDropDownList 来显示database 中表格中的城市,该表格在后台更新。我想在数据库更新时刷新RadDropDownList,但我找不到任何有用的东西。
我的代码在这里:
private void radDropDownList3_KeyUp(object sender, KeyEventArgs e)
{
_result = radDropDownList3.DropDownListElement.Text;
bool any = radDropDownList3.DropDownListElement.Items.Any(item => item.Text == _result.Trim());
if (e.KeyCode == Keys.Enter && !any)
{
try
{
string city = ArToFa(_result);
using (var bas = new SaleToFreightageEntities())
{
bas.Tariff.Add(new Tariff { City = city });
bas.SaveChanges();
}
MessageBox.Show(@"item added.");
tariffBindingSource.ResetBindings(true);
radDropDownList3.Rebind();
radDropDownList3.Refresh();
radDropDownList2.Enabled = false;
_result = "";
}
catch (Exception ex)
{
if (ex.GetBaseException().Message.Contains("Cannot insert duplicate key row"))
MessageBox.Show(@"duplicated item!", @"", MessageBoxButtons.OK,
MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
_result = "";
}
}
}
【问题讨论】:
-
您是否尝试使用 timer+backgroundWorker 询问 db 以及 db 是否更改更新 datesource raddropdownlist?
-
不,我手动更新数据库,我希望在更新数据库时,radDropDownList 在其末尾显示最后插入到数据库的对象
-
如果您在后台数据库中更新之后重新绑定您的 raddropdownlist。分享您的代码。
-
让我解释一下,我有一个带有数据源绑定的“radDropDownList”,当我在列表中搜索所需的项目时,如果列表不包含该键入的单词,我就是按下“Enter”,在“radDropDownList3_KeyUp”事件中,它将被添加到数据库中,但我希望当它添加到数据库时,“radDropDownList”也显示新添加的项目,