ASPX templates
Version 4.x > ASPX templates > Adding Checkbox to bizform edit data View modes: 
User avatar
Member
Member
Raymond A - 12/7/2011 1:03:34 PM
   
Adding Checkbox to bizform edit data
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());


}

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 12/8/2011 8:59:33 AM
   
RE:Adding Checkbox to bizform edit data
Hello,

I've created such a delete method and it seems to work:



protected void Delete_Click(object sender, EventArgs e)
{

DataView dv = (DataView)this.gridData.GridView.DataSource;

int count = 1;

string formid = "0";

if (Request.QueryString["formid"] != null)
{
formid = Request.QueryString["formid"];
}

CMS.FormEngine.BizFormInfo bfi = CMS.FormEngine.BizFormInfoProvider.GetBizFormInfo(System.Convert.ToInt32(formid));


foreach (DataRow item in dv.Table.Rows)
{
if (gridData.SelectedItems.Contains(count.ToString()))
{
int entryID = System.Convert.ToInt32(item[0]);

CMS.FormEngine.BizFormItem bfii = new BizFormItem(item,CMS.SettingsProvider.DataClassInfoProvider.GetClassName(bfi.FormClassID));
bfii.Delete();


}
count++;
}

gridData.ReloadData();
}



You have to add the following key to the file \CMSModules\Bizforms\Tools\BizForm_Edit_Data.xml:

<key name="ShowSelection" value="true" />

Please note, that this is only a fast coded example and it's highly probable I've missed some security checks.

Best regards,
Boris Pocatko