本文介绍了数据网格中绑定值的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
海,
我在datagrid中遇到错误.首先我创建了一个数据表,然后添加了行和列.然后我必须将其绑定到datagrid中.我没有在datagrid中获取值.请Plz帮我.以下是代码.
Hai,
I am getting error in datagrid.First I has created a datatable.Then I added rows and columns.Then I have to bound it into datagrid.I am not getting the values in datagrid.Plz help me.Below is a code.
private void button1_Click(object sender, System.EventArgs e)
{
DataTable table1;
DataRow row1, row2, row3, row4;
table1 = new DataTable("Customers");
DataColumn firstName = new DataColumn("First Name");
firstName.DataType = System.Type.GetType("System.String");
table1.Columns.Add(firstName);
DataColumn lastName = new DataColumn("Last Name");
lastName.DataType = System.Type.GetType("System.String");
table1.Columns.Add(lastName);
DataColumn phone = new DataColumn("Phone");
phone.DataType = System.Type.GetType("System.String");
table1.Columns.Add(phone);
DataColumn id = new DataColumn("ID");
id.DataType = System.Type.GetType("System.Int32");
table1.Columns.Add(id);
row1 = table1.NewRow();
row1["First Name"] = "A";
row1["Last Name"] = "B";
row1["Phone"] = "(555) 333-4444";
row1["ID"] = 1;
table1.Rows.Add(row1);
row2 = table1.NewRow();
row2["First Name"] = "B";
row2["Last Name"] = "C";
row2["Phone"] = "(555) 333-4445";
row2["ID"] = 2;
table1.Rows.Add(row2);
row3 = table1.NewRow();
row3["First Name"] = "E";
row3["Last Name"] = "R";
row3["Phone"] = "(555) 333-4445";
row3["ID"] = 3;
table1.Rows.Add(row3);
row4 = table1.NewRow();
row4["First Name"] = "W";
row4["Last Name"] = "K";
row4["Phone"] = "(555) 333-4447";
row4["ID"] = 4;
table1.Rows.Add(row4);
DataSet dataset1 = new DataSet();
dataset1.Tables.Add(table1);
dataGrid1.SetDataBinding(dataset1, "Customers");
}
}
我在最后一行收到错误消息:"datagrid不包含SetDataBinding的定义."请帮我
I am getting error in the lastline " datagrid does not contain a definition for SetDataBinding" occurs.Plz help me
推荐答案
dataGrid1.DataSource=dataset1.Tables[0] ;
这篇关于数据网格中绑定值的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!