我想选择一行并对它的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填充的
DataTable代码-
protected DataTable GetHeadlineData(SqlDataReader rdr)
{
DataTable headlineTable = new DataTable();
headlineTable.Load(rdr)
headlineTable.PrimaryKey = new DataColumn[] { headlineTable.Columns["ID"] };
return headlineTable;
}PageLoad代码-
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.发布于 2012-05-21 22:47:40
最终起作用的是使用RowClick事件而不是SelectionChanged。
发布于 2012-05-19 19:21:47
尝试将您的代码从Page_Load移动到Page_Init方法。在这种情况下,一切都应该像预期的那样工作。
发布于 2012-10-04 18:33:55
<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" DataSourceID="AccessDataSource1"
KeyFieldName="CustomerID" Width="100%">
</dx:ASPxGridView>您必须提供唯一的Ky列名KeyFieldName="Unique Name"
https://stackoverflow.com/questions/10656579
复制相似问题