Hi ,
Im currently adding a feature to the Bizform edit data page;i added a checkbox to the datagrid and a button to the page.
The button allow one to delete the various rows which have been checked.
The problem is that the state of the checkboxes are not maintained sinc the datagrid is processed on the page before the button click event.
When i disable the databinding of the datagrid on postback the datarow view containing the record doens't have a dataitem.
Here is the datagrid modification:
<asp:Button ID="btnDelete" runat="server" Text="Delete checked items" OnClick="btnDelete_Click" OnClientClick="return DeleteConfirm();" />
<asp:GridView ID="gridData" runat="server" AutoGenerateColumns="false" CellPadding="3" AllowSorting="true"
CssClass="UniGridGrid" AllowPaging="true" PageSize="20" OnPageIndexChanging="gridData_PageIndexChanging" OnSorting="gridData_sort">
<HeaderStyle HorizontalAlign="Left" CssClass="UniGridHead" />
<Columns>
<asp:TemplateField ItemStyle-Wrap="false">
<HeaderTemplate>
Select All
<input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);"
runat="server" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" EnableViewState="true" />
<asp:ImageButton runat="server" ID="btnEdit" ToolTip='<%#editToolTip %>' ImageUrl='<%#"~/App_Themes/" + this.Theme + "/Images/CMSModules/BizForms/edit.gif"%>' />
<asp:ImageButton runat="server" ID="btnDelete" ToolTip='<%#deleteToolTip %>' ImageUrl='<%#"~/App_Themes/" + this.Theme + "/Images/CMSModules/BizForms/delete.gif"%>'
CommandName="delete" OnCommand="btnDelete_OnCommand" OnClientClick="return DeleteConfirm();" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Here is the method to delete rows checked:
protected void btnDelete_Click(object sender, EventArgs e)
{
// Check 'DeleteData' permission
if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.form", "DeleteData"))
{
RedirectToCMSDeskAccessDenied("cms.form", "DeleteData");
}
// Select the checkboxes from the GridView control
for (int i = 0; i < gridData.Rows.Count; i++)
{
GridViewRow row = gridData.Rows;
bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;
if (isChecked)
{
// Column 2 is the name column
GeneralConnection genConn = ConnectionHelper.GetConnection();
IDataClass formRecord = DataClassFactory.NewDataClass(this.formName, ((DataRowView)row.DataItem)[0], genConn);
if (!formRecord.IsEmpty())
{
// Delete selected form record.
formRecord.Delete();
// Update number of entries in BizFormInfo
BizFormInfo bfi = BizFormInfoProvider.GetBizFormInfo(this.formId);
if (bfi != null)
{
BizFormInfoProvider.RefreshDataCount(bfi.FormName, bfi.FormSiteID);
}
}
}
}
UrlHelper.Redirect(Page.Request.Url.ToString());
}