前台代码 Width="90%" SkinID="skDev" CssFilePath="~/App_Themes/DevEx/{0}/styles.css" CssPostfix="DevEx">
<%#Container.ItemIndex+1 %>
/dx:GridViewDataTextColumn
/dx:GridViewDataTextColumn
/dx:GridViewDataTextColumn
/dx:GridViewDataTextColumn
/dx:GridViewDataTextColumn
/dx:GridViewDataTextColumn
/dx:GridViewDataTextColumn
/dx:GridViewDataTextColumn
/dx:GridViewDataTextColumn
</Columns>
后台:
public partial class BuildingMaterials : System.Web.UI.Page
{
public string pid
{
get
{
return Request["pid"];
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string pid = Request["pid"];
List<sb> xsb = GetSbList();
this.ASPxGridView1.DataSource = xsb;
this.ASPxGridView1.DataBind();
}
}
public string a;
public List<sb> GetSbList()
{
GreenInterface g = new GreenInterface();
var xsb = new sb();
var ctx = new Linq.DBPSDataContext();
var ctx1 = new Linq.DBQSDataContext();
var xsbList = new List<sb>();
var temp = new sb();
string sql = "select prod_OrgName,prod_NO,prod_Name,Count,prod_Unit,prod_Price,DealTotal from T_SubOrders group by prod_OrgName,prod_NO,prod_Name,Count,prod_Unit,prod_Price,DealTotal";
DataTable dt = g.Query(sql,ConnectionStrings.DBPS).Tables[0];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (a != dt.Rows[i]["prod_OrgName"].ToString())
{
string b = dt.Rows[i]["prod_OrgName"].ToString();
temp.ID = i;
temp.单位 = "报价";
temp.单价 = "800";
xsbList.Add(temp);
}
xsb.ID = i;
xsb.物料组 = dt.Rows[i]["prod_OrgName"].ToString();
xsb.物料号 = dt.Rows[i]["prod_NO"].ToString();
xsb.物料名称 = dt.Rows[i]["prod_Name"].ToString();
xsb.数量 = dt.Rows[i]["Count"].ToString();
xsb.单位 = dt.Rows[i]["prod_Unit"].ToString();
xsb.单价 = dt.Rows[i]["prod_Price"].ToString();
xsb.总价 = dt.Rows[i]["DealTotal"].ToString();
a = dt.Rows[i]["prod_OrgName"].ToString();
xsbList.Add(xsb);
}
}
return xsbList;
}
public class sb
{
public int ID;
public string 物料组;
public string 物料号;
public string 物料名称;
public string 数量;
public string 单位;
public string 单价;
public string 总价;
public string 增减项;
}
一直显示这个错误:其他信息: A primary key field specified via the KeyFieldName property is not found in the underlying data source. Make sure the field name is spelled correctly. Pay attention to the character case.
我主键也设置了 为什么还显示这个
A primary key field specified via the KeyFieldName property is not found in the underlying data source. Make sure the field name is spelled correctly. Pay attention to the character case.
错误的大概意思是 你没有通过 “KeyFieldName” 属性来 设置主键,并且确定主键 拼写正确。