0

我想选择一行并用它的 Id 列做一些事情,但是它不起作用,我遇到了最后提到的错误。这是我得到的-

ASPxGridView 片段 -

<dx:ASPxGridView ID="ASPxGridView1" runat="server" Font-Names="Arial" Font-Size="Small"
  Width="100%" ClientInstanceName="grid" oncustomcallback="grid_CustomCallback"                                              
  onbeforegetcallbackresult="ASPxGridView1_BeforeGetCallbackResult" 
  EnableCallBacks="False" EnableRowsCache="False" KeyFieldName="ID">

... Columns here ...

<ClientSideEvents ContextMenu="OnContextMenu" SelectionChanged="OnSelectionChanged" />      
</dx:ASPxGridView>

注意:网格通过 DataTable 填充

数据表代码 -

protected DataTable GetHeadlineData(SqlDataReader rdr)
{
    DataTable headlineTable = new DataTable();        
    headlineTable.Load(rdr)
    headlineTable.PrimaryKey = new DataColumn[] { headlineTable.Columns["ID"] };
    return headlineTable;
}

页面加载代码 -

DataTable dt= new DataTable();    
dt= FillGrid(); //this function internally calls the above GetHeadlineData function
Session["headTable"] = dt;
ASPxGridView1.DataSource = Session["headTable"];
ASPxGridView1.KeyFieldName = "ID";
ASPxGridView1.DataBind();

SelectionChanged 函数 -

    function OnSelectionChanged(s, e) {              
        grid.GetSelectedFieldValues("ID", OnGetSelectedFieldValues);            
    }

    function OnGetSelectedFieldValues(result) {
        for (var i = 0; i < result.length; i++)
            for (var j = 0; j < result[i].length; j++) {
                document.getElementById('selectedRowDiv').innerHTML = result[i];                    
            }
    }        

我得到的错误 -

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.
4

3 回答 3

1
 <dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" DataSourceID="AccessDataSource1"
            KeyFieldName="CustomerID" Width="100%">
                    </dx:ASPxGridView>

您必须提供唯一的 Ky 列名KeyFieldName="Unique Column Name"

于 2012-10-04T10:33:55.413 回答
1

尝试将您的代码从 Page_Load 移动到 Page_Init 方法。在这种情况下,一切都应该按预期工作。

于 2012-05-19T11:21:46.823 回答
0

最终起作用的是使用 RowClick 事件而不是 SelectionChanged。

于 2012-05-21T14:47:40.390 回答