views:

451

answers:

1

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?

+2  A: 

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

Muhammad Akhtar