数据挷定问题
DataTable pvdt=new DataTable();
pvdt.Columns.Add(new DataColumn( "id "));
pvdt.Columns.Add(new DataColumn( "Tvlae "));
DataRow pvdr;
pvdr = pvdt.NewRow();
pvdr[ "id "] = 1;
pvdr[ "Tvlae "]= "高级管理员 ";
pvdt.Rows.Add(pvdr);
pvdr = pvdt.NewRow();
pvdr[ "id "] = 2;
pvdr[ "Tvlae "] = "管理员 ";
pvdt.Rows.Add(pvdr);
pvdr = pvdt.NewRow();
pvdr[ "id "] = 3;
pvdr[ "Tvlae "] = "普通用户 ";
pvdt.Rows.Add(pvdr);
dlpv.DataSource = pvdt;
dlpv.DataValueField = Convert.ToString(pvdr[ "id "]);
dlpv.DataTextField = Convert.ToString(pvdr[ "Tvlae "]);
dlpv.DataBind();
出错提示:DataBinding:“System.Data.DataRowView”不包含名为“普通用户”的属性。
新手来的!!
------解决方案--------------------dlpv.DataValueField = "id ";
dlpv.DataTextField = "Tvlae ";
dlpv.DataSource = pvdt;
dlpv.DataBind();
------解决方案--------------------dlpv.DataValueField = Convert.ToString(pvdr[ "id "]);
dlpv.DataTextField = Convert.ToString(pvdr[ "Tvlae "]);
=================
dlpv.DataValueField = "id ";
dlpv.DataTextField = "Tvlae ";