Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
165
Adding empty row by client side - More than one row
posted

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

Parents
No Data
Reply Children