Hello,
I have really some problems using the webdatagrid in order to make simple CRUD with a database.
I have my grid with some data and outside of my grid, I have "new row" button, "edit" button, "delete" button and "save" and "cancel" button.
The "add new" and "delete" row are now managed, but I have lot of difficulties with edit.
When I click on edit, all cells in my grid become editable, I could change value I want, but when I click save, I have this error:
Sys.WebForms.PageRequestManagerServerErrorException: Table doesn't have a primary key
But what I want is only make my own treatments (so update in database) taking the value entered in my grid.
In other words, when I click on save, I would like to have my postback, then run some code then go back to my grid, but I could not due to this error.
Just a precision: my grid is binded in code behind, and I do not use SQLDataSources.
Please find the code I used for my web datagrid:
<ig:WebDataGrid ID="GridSpecBottom" runat="server" AutoGenerateColumns="False" DataKeyFields="NO_IN_ROW" AjaxIndicator-Enabled="False" oninit="GridSpecBottom_Init" onrowadding="GridSpecBottom_RowAdding" onrowupdating="GridSpecBottom_RowUpdating" > <Columns> <ig:BoundDataField DataFieldName="NO_IN_ROW" Key="NO_IN_ROW" Width="40px"> <Header Text="<%$ Resources:Labels, lblNO_IN_ROW %>" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="ARTNO" Key="ARTNO" Width="40px"> <Header Text="<%$ Resources:Labels, lblARTNO %>" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="ARTICLENO" Key="ARTICLENO" Width="60px"> <Header Text="<%$ Resources:Labels, lblARTICLENO %>" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="EXTRA1" Key="EXTRA1" Width="100px"> <Header Text="<%$ Resources:Labels, lblEXTRA1 %>" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="DESCRIP" Key="DESCRIP" Width="250px"> <Header Text="<%$ Resources:Labels, lblDESCRIP %>" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="POSITION" Key="POSITION" Width="140px"> <Header Text="<%$ Resources:Labels, lblPOSITION %>" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="QUANTITY" Key="QUANTITY" Width="40px"> <Header Text="<%$ Resources:Labels, lblQUANTITY %>" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="EXTRA2" Key="EXTRA2" Width="40px"> <Header Text="<%$ Resources:Labels, lblEXTRA2 %>" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FIELD1" Key="FIELD1" Width="80px"> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FIELD2" Key="FIELD2" Width="80px"> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FIELD3" Key="FIELD3" Width="80px"> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FIELD4" Key="FIELD4" Width="80px"> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FIELD5" Key="FIELD5" Width="80px"> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FIELD6" Key="FIELD6" Width="80px"> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FIELD7" Key="FIELD7" Width="80px"> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FIELD8" Key="FIELD8" Width="80px"> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FIELD9" Key="FIELD9" Width="80px"> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FIELD10" Key="FIELD10" Width="80px"> </ig:BoundDataField> </Columns> <Behaviors> <ig:EditingCore> <Behaviors> <ig:RowAdding Alignment="Top"> <ColumnSettings> <ig:RowAddingColumnSetting ColumnKey="NO_IN_ROW" ReadOnly="true" /> <ig:RowAddingColumnSetting ColumnKey="ARTNO" EditorID="DDLArtno" /> <ig:RowAddingColumnSetting ColumnKey="EXTRA2" EditorID="DDLUnit" /> </ColumnSettings> <EditModeActions MouseClick="Single" /> </ig:RowAdding> <ig:RowDeleting Enabled="true" /> <ig:CellEditing Enabled = "false"> <ColumnSettings> <ig:EditingColumnSetting ColumnKey="NO_IN_ROW" ReadOnly="true" /> <ig:EditingColumnSetting ColumnKey="ARTNO" EditorID="DDLArtno" /> <ig:EditingColumnSetting ColumnKey="EXTRA2" EditorID="DDLUnit" /> </ColumnSettings> <EditModeActions MouseClick="Single" /> </ig:CellEditing> </Behaviors> </ig:EditingCore> <ig:Selection CellClickAction="Row" RowSelectType="Single"> </ig:Selection> <ig:RowSelectors> </ig:RowSelectors> </Behaviors> <EditorProviders> <ig:DropDownProvider ID="DDLArtno"> <EditorControl runat="server" DisplayMode="DropDownList" DropDownContainerHeight="100px" DropDownContainerWidth="100px" DataKeyFields="ARTNO"> <DropDownItemBinding TextField="YAR" ValueField="YAR"/> <Items> <ig:DropDownItem Selected="False" Text="YAR" Value="YAR"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="BRA" Value="BRA"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="LIN" Value="LIN"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="BUT" Value="BUT"> </ig:DropDownItem> </Items> </EditorControl> </ig:DropDownProvider> <ig:DropDownProvider ID="DDLUnit"> <EditorControl runat="server" DisplayMode="DropDownList" DropDownContainerHeight="100px" DropDownContainerWidth="100px" DataKeyFields="UNIT"> <DropDownItemBinding TextField="M" ValueField="M"/> <Items> <ig:DropDownItem Selected="False" Text="CM" Value="CM"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="PCS" Value="PCS"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="YD" Value="YD"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="KG" Value="KG"> </ig:DropDownItem> </Items> </EditorControl> </ig:DropDownProvider> </EditorProviders></ig:WebDataGrid>
Thanks for your help
Best Regards
Damien
Hello Damien,
What data source do you bind the WebDataGrid to?
For example if you are using OleDbDataAdapter,
your database table may have a primary key
but it is not the default behaviour of a DataAdapter to retrieve that information,
so the DataTable you populate has no primary key.
If you want to retrieve the PK information
then you have to set the MissingSchemaAction property of your DataAdapter to AddWithKey instead of the default Add.
You have an OleDbDataAdapter.
Set its MissingSchemaAction property to AddWithKey.
Let me know if you need more assistance.
Hello Tsvetelina,
Thanks for your answer.
I do not use an OleDbDataProvider bur directly a dataset to bind my grid. In fact, I fill a dataset with data coming from a webservice.Here is the way I am binding the datagrid.
DataSet
dsSpecification = new DataSet();
dsSpecificBottomGrid = getProxy.GetTableView(builderGridBottom.ToString()); dsSpecification.Tables.Add(dsSpecificBottomGrid.Tables[0].Copy()); dsSpecification.Tables[0].TableName =
dsSpecificBottomGrid = getProxy.GetTableView(builderGridBottom.ToString());
dsSpecification.Tables.Add(dsSpecificBottomGrid.Tables[0].Copy());
dsSpecification.Tables[0].TableName =
"SpecificBottomGrid";
if (GridSpecBottom != null){ try{ GridSpecBottom.ClearDataSource(); GridSpecBottom.Rows.Clear(); } catch { } GridSpecBottom.DataSource = dsSpecification.Tables[ "SpecificBottomGrid"].DefaultView; GridSpecBottom.DataBind(); GridSpecBottom.RequestFullAsyncRender(); } So I do not know how could I set the primary key, but is it mandatory to set a primary key? The only thing I would like is when I click on save, having a postback, then run some code then go back to my grid, but I could not due to this error. Thanks again for your help. Best Regards Damien
if (GridSpecBottom != null){
try{ GridSpecBottom.ClearDataSource(); GridSpecBottom.Rows.Clear(); }
GridSpecBottom.ClearDataSource();
GridSpecBottom.Rows.Clear();
}
catch { } GridSpecBottom.DataSource = dsSpecification.Tables[
GridSpecBottom.DataSource = dsSpecification.Tables[
"SpecificBottomGrid"].DefaultView; GridSpecBottom.DataBind(); GridSpecBottom.RequestFullAsyncRender(); } So I do not know how could I set the primary key, but is it mandatory to set a primary key? The only thing I would like is when I click on save, having a postback, then run some code then go back to my grid, but I could not due to this error. Thanks again for your help. Best Regards Damien
GridSpecBottom.DataBind();
GridSpecBottom.RequestFullAsyncRender();
So I do not know how could I set the primary key, but is it mandatory to set a primary key? The only thing I would like is when I click on save, having a postback, then run some code then go back to my grid, but I could not due to this error.
Thanks again for your help.
Thank you for the clarification.
You should set key when you have enabled AutoCrud.
It can be done by the below way:
DataColumn[] PrimaryKeyColumns = new DataColumn[1];
PrimaryKeyColumns[0] = table.Columns["id"];
table.PrimaryKey = PrimaryKeyColumns;
When you have enabled AutoCrud there is no internal mechanism employed:
WebDataGrid attempts to automatically persist changes using the mechanism of the underlying data source.
This means that if the data source control does not support CRUD operations,
you must handle these operations manually to provide such functionality.
Let me know if you have other questions.
Hi Tsevetelina,
Thanks for your answer, and sorry for my silence.
I have tried to look for a solution, but I have always my problem... When you write:
" you must handle these operations manually to provide such functionality"
How could I do this? How handle these operation manually? I could not find any sample of this.
Please could you give us some clues or some examples, please?
Thanks
That's because IG documentation is pretty sparse and difficult to find simple implementation examples.
Their API documentation is pretty poor as well. I haven't actually used in in 6 or 7 years however after revisiting it to update some controls in a legacy app, it appears nothing has changed.