I have to query across several datasources so I query those various places and retrieve bits of information and build a "hand-made" dataset on the fly in my ASP.Net page's code behind. I am using DevExpress' ASPxGridView. After I create my dataset, I bind to it with my ASPxGridView and it shows my data.
I created the GridView columns manually at design time and not bound to a datasource (since I build my own on the fly). I am trying to use the selection features but I keep getting this error:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 4/5/2010 4:33:53 PM
Event time (UTC): 4/5/2010 8:33:53 PM
Event ID: 5139394830804561854bbf78bc97270a
Event sequence: 21
Event occurrence: 2
Event detail code: 0
Exception type: MissingPrimaryKeyException
Exception message: Missing primary key.
I get that I must have to set the primary key somewhere and I have tried setting it where I do the bind...
DataSet MyDS = new DataSet();
DataTable MyTable = MyDS.Tables.Add();
DataColumn keys = new DataColumn;
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "ID";
keys = column;
MyTable.PrimaryKey = keys;
I add several rows rows...no problems
Then I bind:
MyASPxGridView.DataSource = MyDS.Tables;
MyASPxGridView.KeyFieldName = "ID";
All this works fine and I can see my data as I expect. However, when I select a bunch of rows and do a postback, I get the error above. I am not sure where I am going wrong or if I can do what I am trying here...any thoughts would be appreciated!