**你好
将项目添加到网格时出错。
请指导我**
Model1Container Mobl = new Model1Container();
JadvalSabtenam Sabt = new JadvalSabtenam();
Sabt.name = TextBox1.Text;
Sabt.family = TextBox2.Text;
Mobl.AddToJadvalSabtenamSet(Sabt);
Mobl.SaveChanges();
GridView1.DataSource = Sabt;
GridView1.DataBind();
答案 0 :(得分:0)
GridView1.DataSource = Sabt;
GridView1.DataBind();
Sabt
似乎是单个对象。要绑定DataGrid,您需要拥有List<JadvalSabtenam >
或BindingList<JadvalSabtenam>
试试:
List<JadvalSabtenam > dataSource = new List<JadvalSabtenam> {Sabt};
GridView1.DataSource = dataSource;
GridView1.DataBind();
原因是:Grid应该对单个对象做什么?当它的集合中,每个项目对应一行,而每个属性对应的列都非常有意义。
答案 1 :(得分:0)
List<JadvalSabtenam> dataSource = new List<JadvalSabtenam> { Sabt };
GridView1.DataSourceID = "";
GridView1.DataBind();