// 2005.01.09 - jorn, string optimize private string CreateSelectRows(bool tree, string parentValue, int level, RowCell cell) { StringBuilder s = new StringBuilder(string.Empty); bool m_Foreignkeyselected = false; for (int i = 0; i < Table.Rows.Count; i++) { string optionValue = Table.Rows[i].PrimaryKeyValues; if (!string.IsNullOrEmpty(IdentityColumn) && Table.Rows[i][IdentityColumn].Value != null) { optionValue = Table.Rows[i][IdentityColumn].Value.ToString(); } if (tree) { string treeValue = null; if (Table.Rows[i][TreeParentId].Value != null) { treeValue = Table.Rows[i][TreeParentId].Value.ToString(); } if (treeValue != parentValue || Grid.EMPTYSTRINGCONSTANT.Equals(optionValue)) { continue; } } string selected = string.Empty; if (!m_Foreignkeyselected && optionValue != null) { if (cell.PostBackValue != null) { selected = Equals(optionValue, cell.PostBackValue) ? " selected=\"selected\" " : string.Empty; } else if (cell.Value != null) { selected = Equals(optionValue, cell.Value.ToString()) ? " selected=\"selected\" " : string.Empty; } else if (RememberState && string.IsNullOrEmpty(selected) && (string)Grid.GetState(cell.CellClientId) != null) { selected = (String.Compare(optionValue, Grid.GetState(cell.CellClientId) as string, true) == 0) ? "selected=\"selected\" " : string.Empty; } if (string.IsNullOrEmpty(selected) == false) { m_Foreignkeyselected = true; } } StringBuilder optionText = new StringBuilder(string.Empty); if (level > 0) { for (int j = 0; j < level; j++) { optionText.Append(TreeIndentText); } } try { optionText.Append(BuildDisplayText(i, ValueColumn, Table)); } catch (Exception e) { throw new GridException( string.Format("Error creating select rows for foreign keys ({0})", ColumnId), e); } // if( _enableOnlyTreeLeaf && IsEndLeaf(optionValue) == false ) // s += "<option " + selected + "value=\"" + optionValue + "\">" + optionText; // else s.AppendFormat("<option{0} value=\"{1}\">{2}</option>", selected, optionValue, optionText); if (tree) { s.Append(CreateSelectRows(true, optionValue, level + 1, cell)); } } return(s.ToString()); }
// 2005.01.09 - jorn, string optimize private string CreateRadioButtons(bool tree, string parentValue, int level, RowCell cell) { bool m_Foreignkeyselected = false; StringBuilder s = new StringBuilder(string.Empty); for (int i = 0; i < Table.Rows.Count; i++) { string optionValue = Table.Rows[i].PrimaryKeyValues; if (!string.IsNullOrEmpty(IdentityColumn) && Table.Rows[i][IdentityColumn].Value != null) { optionValue = Table.Rows[i][IdentityColumn].Value.ToString(); } if (tree) { string treeValue = null; if (Table.Rows[i][TreeParentId].Value != null) { treeValue = Table.Rows[i][TreeParentId].Value.ToString(); } if (treeValue != parentValue || Grid.EMPTYSTRINGCONSTANT.Equals(optionValue)) { continue; } } if (i != 0) { if (m_Rowcounter == 0) { s.Append("</tr><tr><td>"); m_Rowcounter = RecordsPerRow; } else { s.Append("<td>"); } } m_Rowcounter--; string selected = string.Empty; if (!m_Foreignkeyselected && optionValue != null) { if (cell.PostBackValue != null) { selected = Equals(optionValue, cell.PostBackValue) ? " checked=\"checked\" " : string.Empty; } else if (cell.Value != null) { selected = Equals(optionValue, cell.Value.ToString()) ? "checked=\"checked\" " : string.Empty; } else if (RememberState && string.IsNullOrEmpty(selected) && (string)Grid.GetState(cell.CellClientId) != null) { selected = (String.Compare(optionValue, Grid.GetState(cell.CellClientId) as string, true) == 0) ? "checked=\"checked\" " : string.Empty; } if (string.IsNullOrEmpty(selected) == false) { m_Foreignkeyselected = true; } } StringBuilder optionText = new StringBuilder(string.Empty); if (level > 0) { for (int j = 0; j < level; j++) { optionText.Append(TreeIndentText); } } try { optionText.Append(BuildDisplayText(i, ValueColumn, Table)); } catch (Exception e) { throw new GridException(string.Format("Error creating radio buttons rows for foreign keys ({0})", ColumnId), e); } StringBuilder javascript = new StringBuilder(); if (AutoPostback || string.IsNullOrEmpty(ConfirmMessage) == false) { StringBuilder eventScript = new StringBuilder(" onchange=\""); if (string.IsNullOrEmpty(ConfirmMessage) == false) { eventScript.AppendFormat(" if(confirm('{0}')) ", ConfirmMessage); } string link = Grid.EnableCallBack && !ForcePostBack?Asynchronous.GetCallbackEventReference(Grid, string.Format("ElementPostBack!{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues), false, string.Empty, string.Empty) : Grid.Page.ClientScript.GetPostBackEventReference(Grid, string.Format( "ElementPostBack!{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues)); eventScript.AppendFormat("{0}\"", link); javascript.Append(eventScript); } s.AppendFormat( "<input type=\"radio\" id=\"rb_{0}_{1}\" {4} name=\"{0}\" value=\"{1}\" {3} /><label class=\"wglabel\" for=\"rb_{0}_{1}\">{2}</label>", cell.CellClientId, optionValue, optionText, selected, javascript); if (tree) { s.Append(CreateRadioButtons(true, optionValue, level + 1, cell)); } } return(s.ToString()); }