我有一個Telerik RadDropDownList
顯示在database
表中的城市,在後臺得到更新。每當數據庫更新時,我都想刷新RadDropDownList
,但我找不到任何有用的信息。 我的代碼是在這裏:如何強制telerik 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 = "";
}
}
}
你是否嘗試使用計時器+ backgroundWorker問db,如果db更新更新datesource raddropdownlist? –
不,我手動更新數據庫,並且希望在數據庫更新時,radDropDownList在數據庫末尾顯示最後插入的數據庫對象 – kavir
如果您在後面的數據庫中更新,請重新綁定您的raddropdownlist。分享你的代碼。 –