Hello there guys,
another day, another problem: I just want to add a empty row everytime an user clicks on a button.
My approach: I add it client-side and on the initialize event I fill the dropdown, I have.
I needed to add a dummy-behavior to make it working:
<Behaviors> <ig:EditingCore> <Behaviors> <ig:RowAdding> <AddNewRowClientEvents /> <EditModeActions EnableF2="false" /> </ig:RowAdding> </Behaviors> </ig:EditingCore> </Behaviors>
The button is just like:
<stgwc:ImageLinkButton runat="server" ID="btnCreateNewAttribute" ImageUrl="~/Images/base/Icons/16x16/add2.png" ToolTip="Add new Attribute" OnClientClick="addEmptyRow(); return false;" />
note: the return false is not tested, but doesnt matter anyway.
Now the BLOCKED SCRIPT
function addEmptyRow() { var grid = $find("<%=dgrIndRoleAttributes.ClientID%>"); // get a reference to the grid var values = new Array(grid.get_columns().get_length()); // create a new empty row grid.get_rows().add(values) // add the new row }
And the initialize in c#:
private void dgrIndRoleAttributes_InitializeRow(object sender, RowEventArgs e) { long indRoleAttribId = Convert.ToInt64(e.Row.Items.FindItemByKey("bdIndRoleAttributeId").Value); Control control = e.Row.Items.FindItemByKey(COL_INDROLEATTRIUBDESC).FindControl("ddlIndRoleAttribDescr"); FillIndRoleAttribDropDown(control as DropDown, indRoleAttribId); control = e.Row.Items.FindItemByKey(COL_INDROLEATTRIBVAL).FindControl("txtIndRoleAttribValue"); (control as TextEdit).Text = MapIndRoleAttribValue(indRoleAttribId); control = e.Row.Items.FindItemByKey(COL_INDROLEATTRIBACTION).FindControl("btnDeleteAttribute"); JScriptHelper.RegisterConfirmBeforeDelete(control as ImageLinkButton); }
Does not matter, just some business logic.
Well, on the first klick it works fine, but then it just overrides the new row, no matter how many times I click.
Is there a reason to do this? Does the Add_row not check the rows but the datasource, where (I guess so?) the new entry isnt added?
Thanks for your response and have a nice weekend
Müller Matthias
There is definitly something wrong: When I check the grid.Rows.Count, the new Row isnt even in there.
Hello Matthias ,
Thank you for posting in our forum.
How are the CRUD operations handled for your grid?
In general if you’re data source supports AutoCRUD then the grid will automatically add the new row to the data source. You can check which data sources support AutoCRUD here:
http://help.infragistics.com/NetAdvantage/ASPNET/2011.1/CLR4.0/?page=WebDataGrid_Supported_Data_Sources.html
If your data source doesn’t support AutoCRud then you’ll need to implement Manual CRUD in order to manually apply the changes made to the grid on the related CRUD event. In the case of adding a new row that would be the RowAdding event. There’s an example on how to implement manual crud in order to persist changes in the grid here:
http://es.infragistics.com/community/blogs/developer_support/archive/2012/02/03/webdatagrid-manual-crud.aspx
Let me know if you have any questions about this.
Best Regards,
Maya Kirova
Developer Support Engineer II
Infragistics, Inc.
http://es.infragistics.com/support
Hi Maya,
thanks for the answer.
Since I could not wait half a year for a reply and tinkered a workarround.
So the case is closed for me.
With best regards
Matthias