Question

I am using a CheckBoxList inside of a FormView with an ObjectDataSource. In order to bind the selected values to the CheckBoxList I am using the FormView_DataBound event to find the CheckBoxList and set the selected items. This works fine.

Now saving these values is becoming problematic. Is it possible to use the ObjectDataSource to update these values, or do I have to save them after the ObjectDataSource saves?

Was it helpful?

Solution

put this code in formview inserting event... Iterate checkbox list and add selected item in datatable and pass 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 iterate datatable in your BLL and save into DB accordingly

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top