protected override void OnInit(EventArgs e) { base.OnInit(e); this.btnConfirm = new CButton { IconName = "check", Text = string.IsNullOrEmpty(this.ConfirmButtonResourceKey) ? Resources.Accept : Resources.ResourceManager.GetString(this.ConfirmButtonResourceKey), CausesValidation = false, }; btnConfirm.Command += (s, ea) => { if (this.Confirm != null) { this.Confirm(s, new CommandEventArgs(string.Empty, hfArgumentData.Value)); } hfArgumentData.Value = ""; }; this.Controls.Add(this.btnConfirm); hfArgumentData = new CHiddenField { ClientIDMode = System.Web.UI.ClientIDMode.Static, ID = ClientID + "_hfArgumentData" }; Controls.Add(hfArgumentData); this.RegisterScripts(); }
protected override void OnInit(EventArgs e) { base.OnInit(e); btnHiddenFilter = new CButton { ID = this.ID + "_btnHiddenFilter", CausesValidation = false, IconName = "filter", }; btnHiddenFilter.Style.Add("display", "none"); btnHiddenFilter.Click += (s, ea) => { if (FilterApplied != null) { FilterApplied(s, ea); } }; this.Controls.Add(btnHiddenFilter); }
protected override void OnInit(EventArgs e) { base.OnInit(e); EmptyDataRowStyle.CssClass = "empty-data"; this.EmptyDataText = Messages.NoDataFound; if (ShowExportAsExcelButton) { btnHiddenExportAsExcel = new CButton { ID = this.ClientID + "_btnHiddenExportAsExcel", CausesValidation = false, IconName = "file-excel-o" }; btnHiddenExportAsExcel.Style.Add("display", "none"); btnHiddenExportAsExcel.Click += (s, ea) => { if (ExportingAsExcel != null) { ExportingAsExcel(s, ea); } }; ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnHiddenExportAsExcel); } }
protected override void Render(HtmlTextWriter writer) { if (this.AllowPaging && this.ShowPageSize && !this.ShowGridHeader) { throw new InvalidOperationException(string.Format("ShowPageSize for grid {0} requires ShowGridHeader to be true.", this.ID)); } System.Text.StringBuilder builder = new System.Text.StringBuilder(); string btnAddOutput = string.Empty, btnReload = string.Empty, btnFilter = string.Empty, btnExcel = string.Empty, Tools = string.Empty, ddlPageSizeOutput = string.Empty, popupButtons = string.Empty; #region Add Button if (ShowAddButton) { builder.Clear(); CButton btnAdd = new CButton { ClientIDMode = System.Web.UI.ClientIDMode.Static, ID = this.ClientID + "_btnAdd", Text = Resources.NewItem, IconName = "plus-square-o", OnClientClick = this.Page.ClientScript.GetPostBackEventReference(this, "New") + " ; return false;" }; btnAdd.RenderControl(new HtmlTextWriter(new StringWriter(builder))); btnAddOutput = builder.ToString(); } #endregion #region Excel Button if (ShowExportAsExcelButton) { builder.Clear(); CButton btn = new CButton { ClientIDMode = System.Web.UI.ClientIDMode.Static, ID = this.ClientID + "_btnExcel", Text = Resources.ExportAsExcel, IconName = "file-excel-o" }; btn.RenderControl(new HtmlTextWriter(new StringWriter(builder))); btnExcel = builder.ToString(); string script = (";$(function(){ $(document.body).on('click','#btnExcel',function(){$('#btnExportAsExcel').click();return false;}); });").Replace("btnExportAsExcel", btn.ClientID).Replace("btnHiddenExportAsExcel", btnHiddenExportAsExcel.ClientID); ScriptManager.RegisterStartupScript(Page, Page.GetType(), this.ClientID + "_script", script, true); } #endregion #region Reload Button if (ShowReloaCButton) { builder.Clear(); CButton btn = new CButton { ClientIDMode = System.Web.UI.ClientIDMode.Static, ID = this.ClientID + "_btnReload", Text = Resources.Reload, IconName = "refresh", OnClientClick = this.Page.ClientScript.GetPostBackEventReference(this, "Reload") + " ; return false;" }; btn.RenderControl(new HtmlTextWriter(new StringWriter(builder))); btnReload = builder.ToString(); } #endregion #region Filter Button if (ShowFilterButton) { builder.Clear(); CButton btn = new CButton { ClientIDMode = System.Web.UI.ClientIDMode.Static, ID = this.ClientID + "_btnFilter", Text = Resources.Filter, IconName = "filter", OnClientClick = "return false;" }; btn.Attributes.Add("data-toggle", "modal"); btn.Attributes.Add("data-target", "#" + this.FilterPanelID + "-modal"); btn.RenderControl(new HtmlTextWriter(new StringWriter(builder))); btnFilter = builder.ToString(); } #endregion #region Popups if (Popups.Count > 0) { builder.Clear(); for (int i = 0; i < Popups.Count; i++) { CButton btn = new CButton { ClientIDMode = System.Web.UI.ClientIDMode.Static, ID = this.ClientID + "_popup" + i.ToString(), Text = Popups[i].ButtonText, IconName = Popups[i].ButtonIcon, OnClientClick = "return false;" }; btn.Attributes.Add("data-toggle", "modal"); btn.Attributes.Add("data-target", "#" + Popups[i].PopupID); btn.RenderControl(new HtmlTextWriter(new StringWriter(builder))); } popupButtons = builder.ToString(); } #endregion #region Page Size if (AllowPaging && ShowPageSize) { ddlPageSize = new CDropDownList { SelectedValueMode = DropDownListSelectedValueModes.ClearSelection, ID = this.ClientID + "_ddlPageSize", CausesValidation = false, AutoPostBack = true, ToolTip = Resources.ItemsCount }; for (int i = PageSizeFrom; i <= PageSizeTo; i += PageSizeStep) { ddlPageSize.Items.Add(new ListItem { Text = i.ToString(), Value = i.ToString(), Selected = i == PageSize }); } if (ddlPageSize.Items.Count > 0) { builder.Clear(); string postBackScript = this.Page.ClientScript.GetPostBackEventReference(this, "$$", false) + " ; return false;"; postBackScript = postBackScript.Replace("'$$'", "'PageSize$'+document.getElementById('##').value") .Replace("##", ddlPageSize.ID); ddlPageSize.Attributes.Add("onchange", postBackScript); ddlPageSize.RenderControl(new HtmlTextWriter(new StringWriter(builder))); ddlPageSizeOutput = builder.ToString(); // page count text ddlPageSizeOutput += string.Format("<span class='rows-count'>{0} {1} {2}</span>", this.Rows.Count, Resources.From, this.SelectArguments.TotalRowCount.ToString()); } } #endregion #region Freeze Header if (this.FreezeHeader) { string FreezeHeaderScript = @"$(document).ready(function () { $('#" + this.ClientID + "').Scrollable({ ScrollHeight: " + this.FreezeHeight + (AutoWidth ? "" : ", Width: " + this.FreezeWidth) + " }); });"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), this.ClientID + "_freezeHeader", FreezeHeaderScript, true); } #endregion string title = !string.IsNullOrEmpty(this.GridTitleResourceKey) ? Resources.ResourceManager.GetString(this.GridTitleResourceKey) : this.GridTitleText; if (this.ShowGridHeader) { writer.Write(string.Format("<div style='width: {0};' class='section'><h3 class='section-title'>{1}{2}</h3><div style='width : 99%;' class='grid-view-container'>", this.ContainerWidth ?? "99%", title, ddlPageSizeOutput)); } else { writer.Write(string.Format("<div style='width: {0};' class='grid-view-container'>", this.ContainerWidth ?? "99%")); } base.Render(writer); Tools = string.Format("<div class='grid-view-tools' style='width: {0}'>{1}{2}{3}{4}{5}</div>", this.FreezeHeader && !AutoWidth ? FreezeWidth + "px" : "100%", btnAddOutput, btnReload, btnFilter, btnExcel, popupButtons); writer.Write(Tools); if (this.ShowGridHeader) { writer.Write("</div>"); } writer.Write("</div>"); }