protected string GetToolbarButtonData(ToolbarButton btn) { StringBuilder sb = new StringBuilder(); sb.Append("{"); sb.Append("text:'" + btn.Text + "'"); if (!string.IsNullOrEmpty(btn.IconUrl)) { sb.AppendFormat(",icon:'{0}'", btn.IconUrl); } if (btn.Icon != Icons.None) { btn.IconClass = "icon-" + ClientHelper.GetEnum(btn.Icon); } if (!string.IsNullOrEmpty(btn.IconClass)) { sb.AppendFormat(",iconClass:'{0}'", btn.IconClass); } if (!string.IsNullOrEmpty(btn.ID)) { sb.AppendFormat(",id:'{0}'", btn.ID); } if (!string.IsNullOrEmpty(btn.OnClientClick)) { sb.AppendFormat(",onClick:'{0}'", btn.OnClientClick); } if (!btn.Enabled) { sb.Append(",enabled:false"); } if (btn.Menu != null) { this.Controls.AddAt(0, btn.Menu); sb.AppendFormat(",menu:song.getCmp('" + btn.Menu.ID + "')"); } sb.Append("}"); return(sb.ToString()); }
protected override void OnPreRender(EventArgs e) { StringBuilder sb = new StringBuilder(); //sb.AppendLine(Script.BeginTag); // sb.Append("$(function(){"); sb.AppendLine("var colModel=["); for (int i = 0; i < columns.Count; i++) { GridColumn col = columns[i]; sb.Append("{"); sb.AppendFormat("name:\"{0}\"", col.Field); sb.AppendFormat(",display:\"{0}\"", col.Header); sb.Append(",width:" + col.Width); sb.AppendFormat(",align:\"{0}\"", WSH.Web.Common.Helper.ClientHelper.GetEnum(col.Align)); sb.Append(",sortable:" + WSH.Web.Common.Helper.ClientHelper.GetBool(col.Sortable)); if (col.Hidden) { sb.Append(",hide:" + WSH.Web.Common.Helper.ClientHelper.GetBool(col.Hidden)); } if (!string.IsNullOrEmpty(col.Renderer)) { sb.Append(",process:" + col.Renderer); } sb.Append("}"); if (i < columns.Count - 1) { sb.Append(","); } sb.Append(Script.Line); } sb.AppendLine("];"); sb.Append("$(\"#" + this.ID + "\").flexigrid({"); sb.Append("colModel:colModel"); if (this.Buttons.Count > 0) { sb.Append(",buttons:["); for (int i = 0; i < this.Buttons.Count; i++) { ToolbarItem item = Buttons[i]; sb.Append("{"); if (item is ToolbarButton) { ToolbarButton btn = item as ToolbarButton; sb.AppendFormat("displayname:\"{0}\"", btn.Text); if (!string.IsNullOrEmpty(btn.ID)) { sb.AppendFormat(",name:\"{0}\"", btn.ID); } if (btn.Icon != Icons.None || !string.IsNullOrEmpty(btn.IconClass)) { sb.AppendFormat(",bclass:\"{0}\"", btn.Icon == Icons.None ? btn.IconClass : WSH.Web.Common.Helper.ClientHelper.GetIcon(btn.Icon)); } if (!string.IsNullOrEmpty(btn.OnClientClick)) { sb.AppendFormat(",onpress:{0}", btn.OnClientClick); } } else if (item is Separator) { Separator sep = item as Separator; sb.Append("separator:true"); } sb.Append("}"); if (i < Buttons.Count - 1) { sb.Append(","); } } sb.Append("]"); } sb.AppendFormat(",url:{0}", (string.IsNullOrEmpty(Url) ? "cmp.getDefaultUrl()" : "\"" + Url + "\"")); sb.AppendFormat(",dataType:\"{0}\"", (DataType == AjaxDataType.Xml ? "xml" : "json")); sb.Append(",usepager:" + WSH.Web.Common.Helper.ClientHelper.GetBool(usePager)); if (!string.IsNullOrEmpty(title)) { sb.AppendFormat(",title:\"{0}\"", title); } if (!string.IsNullOrEmpty(Width.ToString())) { sb.AppendFormat(",width:\"{0}\"", Width); } if (!string.IsNullOrEmpty(Height.ToString())) { sb.AppendFormat(",height:\"{0}\"", Height.ToString()); } if (PageSize > 0) { sb.Append(",rp:" + PageSize); } sb.AppendLine("});"); //sb.Append("});"); //sb.AppendLine(Script.EndTag); Script.RegisterStartupScript(Page, "FlexGrid-" + this.ID, sb.ToString()); base.OnPreRender(e); }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); StringBuilder sb = new StringBuilder(); sb.AppendLine(""); sb.AppendLine("$(function(){"); sb.AppendLine("var " + this.ID + "=new song.toolbar({id:'" + this.ID + "',renderTo:'#" + this.ClientID + "'});"); int count = Items.Count; if (count > 0) { sb.Append(this.ID + ".add("); for (int i = 0; i < count; i++) { ToolbarItem item = Items[i]; if (item is Separator) { sb.Append("'-'"); } else if (item is ToolbarText) { sb.Append("'" + ((ToolbarText)item).Text + "'"); } else if (item is ToolbarButton) { ToolbarButton btn = item as ToolbarButton; sb.Append(GetToolbarButtonData(btn)); } else { if (item.Controls.Count > 0) { StringBuilder s = new StringBuilder(); for (int j = 0; j < item.Controls.Count; j++) { Control control = item.Controls[j]; string id = control.ClientID; if (!string.IsNullOrEmpty(id)) { this.Controls.Add(control); j--; s.Append("song.dom('" + id + "'),"); } } string dom = s.ToString(); if (dom.EndsWith(",")) { s.Remove(s.Length - 1, 1); } if (string.IsNullOrEmpty(dom)) { sb.Append("''"); } else { sb.Append(s.ToString()); } } } if (i < count - 1) { sb.Append(","); } } sb.Append(");"); } sb.AppendLine(""); sb.AppendLine("});"); // Script.AddCss(this.Page, "ToolbarCss", ClientResourceUrl.ToolbarCss); //Script.AddScript(this.Page, "ToolbarJs", ClientResourceUrl.ToolbarJs); Script.RegisterStartupScript(this.Page, "Toolbar-" + this.ID, sb.ToString()); }