listbox的重新载入问题

fuxiangxin 2007-07-10 05:44:13
用Listbox绑定了数据库代码如下:
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=TestOnline;Integrated Security=True");

SqlDataAdapter da = new SqlDataAdapter("select DepName,DepID,DepAdminTeacherID from TblDepartment", con);
DataTable dt = new DataTable("DepTable");

dt = ds.Tables["DepTable"];

DataSet ds = new DataSet();
da.Fill(ds, "DepTable");
      this.LstDep.DataSource = dt;
this.LstDep.DisplayMember = "DepName";
this.LstDep.ValueMember = "DepID";
想在新加入一条记录后即时的显示出来,但是试图用clear方法清除掉列表框里原有的记录再重新绑定时,提示“设置了datasource属性以后无法修改”
 谁能给我个意见啊?
...全文
118 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wj0728 2008-07-01
  • 打赏
  • 举报
回复
晕死,告诉你一个好的方法,在数据绑定之前
this.LstDep.DataSource = null;
this.LstDep.DataSource = dt;
this.LstDep.DisplayMember = "DepName ";
this.LstDep.ValueMember = "DepID ";
owennol 2007-07-10
  • 打赏
  • 举报
回复
用this.LstDep.DataSource = dt;
this.LstDep.DisplayMember = "DepName";
this.LstDep.ValueMember = "DepID";
绑定后,不能修改

建议用For循环加入Item

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧