How to save items from CheckBoxList to FormView?

I am using CheckBoxList inside FormView with ObjectDataSource . To bind selected values ​​to a CheckBoxList , I use the FormView_DataBound event to find the CheckBoxList and set the selected items. It works great.

Saving these values ​​is now becoming problematic. Is it possible to use ObjectDataSource to update these values ​​or save them after saving ObjectDataSource ?

+3
source share
1 answer

put this code in the formview insertion event ... List the checkboxes and add the highlighted element to datatable and go to your BLL

CheckBoxList chklRoles = (CheckBoxList)frm.FindControl("chklRoles");
    foreach (ListItem liRole in chklRoles.Items)
    {
        if (liRole.Selected)
        {
            SecurityDS.SC_RoleRow drwRoles = dtblRoles.NewSC_RoleRow();
            drwRoles.Name = liRole.Value;
            drwRoles.IsActive = false;
            dtblRoles.Rows.Add(drwRoles);
        }
    }
    e.Values["userRole"] = dtblRoles;

ASPX page code .. parameter type

<InsertParameters>

                    <asp:Parameter Name="userRole" Type="Object" />
                </InsertParameters>

and then repeat the processing of the data in the BLL and save it in the database.

+3
source

Source: https://habr.com/ru/post/1714215/


All Articles