日期:2014-05-17  浏览次数:20708 次

DevExpress中ASPxGridView的一些错误
错误信息:
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. For detailed information, please refer to the http://www.devexpress.com/kbid=KA18689 article.

代码如下:
<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" 
DataSourceID="masterDataSource" KeyFieldName="id" Width="100%">


<asp:SqlDataSource ID="masterDataSource" runat="server" 
providerName="System.Data.SqlClient" SelectCommand="select * from table">
</asp:SqlDataSource>


protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack){
            string connStr = 
WebConfigurationManager.ConnectionStrings["MySql"].ConnectionString;
            masterDataSource.ConnectionString = connStr;
            grid.DataBind(); 
            grid.DetailRows.ExpandRow(0);
        }
    }

数据库表中也设置了主键。
请问怎么修改呢?
------解决方案--------------------
能否贴出SQL语句?SQL查询结果中是否包含所有绑定列?主键列是否叫做"id"?
------解决方案--------------------

    <dx:ASPxGridView ID="Grid" class="Colsed" runat="server" AutoGenerateColumns="False" 
    Settings-VerticalScrollableHeight="300" KeyFieldName="DEPTNAME"
        Theme="BlackGlass" ClientInstanceName="grid" OnCustomUnboundColumnData="Grid_CustomUnboundColumnData"
        EnableViewState="False" EnableTheming="True" SettingsBehavior-AllowFocusedRow="true">



1.这个是我之前写的一个页面上控件,但是我是在后台绑定的数据源,并且这里的KeyFileName并不需要一定绑定主键,这里我是任意绑定的一个字段。希望对LZ有所帮助