当我插入或更新新记录时,我让用户能够立即使用组合框并且记录在那里。我在页面加载事件中填充了组合框。当他们点击更新或创建它时,它会清除旧值并放入从数据库中获取的新值。我的问题是你怎么能只更新组合框,添加或更新新行而不重新加载所有行?
这是我的填充方法:
List<LabelData> labelList = LabelData.getAllLabels();
if (labelList != null)
{
foreach (LabelData l in labelList)
{
cmboBoxPreviousVersion.Items.Add(string.Format("{0} - {1}", l.PackFormatID, l.Description));
}
}
这是.getAllLabels方法
SqlConnection dbConn = null;
List<LabelData> LabelList = new List<LabelData>();
try
{
using (dbConn = new SqlConnection(Properties.Settings.Default["tville"].ToString()))
{
string sql = "SELECT * FROM PFormat";
SqlCommand cmd = dbConn.CreateCommand();
cmd.CommandText = sql;
dbConn.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
LblD l = new LabelData();
l.PFormID = reader.GetInt32(0);
l.Descrip = reader.GetString(1);
l.StockID = reader.GetInt32(2);
l.PPC = reader.GetBoolean(3);
l.PP = reader.GetBoolean(4);
l.PW = reader.GetBoolean(5);
LabelList.Add(l);
}
}
}
}
catch (Exception ex)
{
throw ex;
}
return LabelList;
}