Login
Latest Development Blogs
Forum Topics Post
Browse By Tag
Hi
I found following text in WhitePaper:
How can I use multiple key field?
Regards
Michael
Did you handle your own delete and edit method using DeleteRow and UpdateRow server side method?
If you are not using strongly typed dataset to bind data to WebGrid, you will need to set some property to the datatable, such as primary key, allownull to pass the schema to the WebGrid .
In order to support multiple key field scenario you don't need to set the DataKeyField property in the WebGrid table. We already have a sample of this scenario in HierarchicalGrid.aspx. The OrderDetails has multiply key, OrderID and ProductID, so in the OrderDetails WebGrid definition no DataKeyField property is assigned
<ISWebGrid:WebGridTable Caption="Order Details" DataMember="Order Details">
On the other hand, the Order table which has the primary key OrderID will have to be assigned the DataKeyField property
<ISWebGrid:WebGridTable Caption="Orders" DataKeyField="OrderID" DataMember="Orders">
Hi Glenn
I have a table with 2 Foreignkey-Columns, which together define the Primarykey of this table.
The Columntypes are GUID. Small Batch Update is active.
On WebGrid1_PrepareDataBinding-Event I call RetrieveStructure().
If I add the following 2 Records, I get a Message from Website: The pending changes already contain a record with key ''
First Record:
00000000-0000-0000-0000-000000000001 and 10000000-0000-0000-0000-000000000000
Second Record:
00000000-0000-0000-0000-000000000002 and 10000000-0000-0000-0000-000000000000
On Debugmode I have seen, both columns are type of System.Guid and DataKeyField is not set.
How can I solve this problem?
How are you loading the data the gets bound to the grid? Because, in scenarios where we can bind a Dataset/DataTable in the InitializeDataSource event, we can just specify a composite primary key for the Datatable with those two columns and then the grid will consider both these columns as DataKeyFields.
I bound a DataSet on InitalizeDataSource-Event to WebGrid.
My test show WebGrid does have issue when adding new row with guid column key using BatchUpdate, However the issue is the key value of the guid is clipped so it will only get a few character of the guid not the whole guid. A bug report has been submitted to the developer.
Regarding the issue you are facing, the key is passed as '', after retrieving the dataset you will need to set some property to the datatable, such as primary key, allownull, unless you are already using strongly typed dataset to bind data to WebGrid.
I have a similar problem, i want to work in the webgrid a table with a composite primary key (id_user,id_role) and we only can define a key for the webgrid, what can i do?
what you mean with"specify a composite primary key for the datatable with those two columns" ????
Just quoting from my response earlier
In order to support multiple key field scenario you don't need toset the DataKeyField property in the WebGrid table. We already have a sample of this scenario in HierarchicalGrid.aspx. The OrderDetails has multiply key, OrderID and ProductID, so in the OrderDetails WebGrid definition no DataKeyField property is assigned <ISWebGrid:WebGridTable Caption="Order Details" DataMember="Order Details"> On the other hand, the Order table which has the primary key OrderID will have to be assigned the DataKeyField property<ISWebGrid:WebGridTable Caption="Orders" DataKeyField="OrderID" DataMember="Orders">
In order to support multiple key field scenario you don't need toset the DataKeyField property in the WebGrid table. We already have a sample of this scenario in HierarchicalGrid.aspx. The OrderDetails has multiply key, OrderID and ProductID, so in the OrderDetails WebGrid definition no DataKeyField property is assigned
Thanks for the answer, but in our interface user standar we don't use this kind of webgrid with child grid.
we have a user and we need to assign roles using the webgrid, but the problem is that we have two keys (id_user,id_role).
For add new rows we have the user like a default value and we can add the row without problems
But for edit and delete we have problems, because we have two keys and when we use tha buttoms grid, it shows an error