PageRenderTime 65ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/CMSAdminControls/UI/UniSelector/UniSelector.ascx.cs

https://bitbucket.org/mchudo89/cms.io.rackspace-with-kentico
C# | 2500 lines | 1692 code | 414 blank | 394 comment | 219 complexity | 31a0459bc85f4eb486a223d838203552 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. using System;
  2. using System.Collections;
  3. using System.Data;
  4. using System.Text;
  5. using System.Linq;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Collections.Generic;
  9. using CMS.CMSHelper;
  10. using CMS.ExtendedControls;
  11. using CMS.GlobalHelper;
  12. using CMS.SiteProvider;
  13. using CMS.SettingsProvider;
  14. using CMS.UIControls;
  15. public partial class CMSAdminControls_UI_UniSelector_UniSelector : UniSelector, IPostBackEventHandler, ICallbackEventHandler
  16. {
  17. #region "Private variables"
  18. private bool registerScripts = false;
  19. private string checkBoxClass = null;
  20. private TextHelper th = new TextHelper();
  21. private Hashtable parameters = new Hashtable();
  22. private GeneralizedInfo objectType = null;
  23. private GeneralizedInfo listingObject = null;
  24. private string mListingObjectType = string.Empty;
  25. private string mListingWhereCondition = String.Empty;
  26. private DataSet result = null;
  27. private bool mLoaded = false;
  28. private bool mPageChanged = false;
  29. private int mNewCurrentPage = 0;
  30. private string mEditWindowName = "EditWindow";
  31. private int mEditDialogWindowWidth = 1000;
  32. private int mEditDialogWindowHeight = 700;
  33. private bool mDynamicFirstColumnName = true;
  34. private bool mIsSiteManager = false;
  35. private Dictionary<int, string> mPriorityStyles = new Dictionary<int, string>();
  36. private StringBuilder javaScript = new StringBuilder();
  37. private bool? mButtonNewEnabled = null;
  38. private bool? mButtonEditEnabled = null;
  39. private bool? mButtonRemoveEnabled = null;
  40. #endregion
  41. #region "Delegates and events"
  42. /// <summary>
  43. /// Delegate for additional data bound event.
  44. /// </summary>
  45. /// <param name="sender">Sender object</param>
  46. /// <param name="sourceName">Source name for grid column</param>
  47. /// <param name="parameter">Column (row) grid values</param>
  48. /// <param name="value">Value given from classic grid data bound event</param>
  49. public delegate object AdditionalDataBoundEventHandler(object sender, string sourceName, object parameter, string value);
  50. /// <summary>
  51. /// Event for additional manipulation with uni-selector grid.
  52. /// </summary>
  53. public event AdditionalDataBoundEventHandler OnAdditionalDataBound;
  54. #endregion
  55. #region "Public properties"
  56. /// <summary>
  57. /// Object of the specific given type.
  58. /// </summary>
  59. protected GeneralizedInfo Object
  60. {
  61. get
  62. {
  63. // Make sure that objects specified by given object type exist
  64. if ((objectType == null) && !String.IsNullOrEmpty(ObjectType))
  65. {
  66. objectType = CMSObjectHelper.GetObject(ObjectType);
  67. }
  68. return objectType;
  69. }
  70. }
  71. /// <summary>
  72. /// Type of alternative info object used in multiple picker grid view.
  73. /// </summary>
  74. public GeneralizedInfo ListingObject
  75. {
  76. get
  77. {
  78. // Make sure that objects specified by given object type exist
  79. if ((listingObject == null) && !String.IsNullOrEmpty(ListingObjectType))
  80. {
  81. listingObject = CMSObjectHelper.GetObject(ListingObjectType);
  82. }
  83. return listingObject;
  84. }
  85. }
  86. /// <summary>
  87. /// If true first column is dynamically named by object type info.
  88. /// </summary>
  89. public bool DynamicColumnName
  90. {
  91. get
  92. {
  93. return mDynamicFirstColumnName;
  94. }
  95. set
  96. {
  97. mDynamicFirstColumnName = value;
  98. }
  99. }
  100. /// <summary>
  101. /// If true, uni-selector is used in site manager.
  102. /// </summary>
  103. public bool IsSiteManager
  104. {
  105. get
  106. {
  107. return mIsSiteManager;
  108. }
  109. set
  110. {
  111. mIsSiteManager = value;
  112. }
  113. }
  114. /// <summary>
  115. /// Name of alternative grid view listing object type.
  116. /// </summary>
  117. public string ListingObjectType
  118. {
  119. get
  120. {
  121. return mListingObjectType;
  122. }
  123. set
  124. {
  125. mListingObjectType = value;
  126. }
  127. }
  128. /// <summary>
  129. /// Name of alternative grid view listing object type.
  130. /// </summary>
  131. public string ListingWhereCondition
  132. {
  133. get
  134. {
  135. return mListingWhereCondition;
  136. }
  137. set
  138. {
  139. mListingWhereCondition = value;
  140. }
  141. }
  142. /// <summary>
  143. /// Dialog control identifier.
  144. /// </summary>
  145. protected string Identifier
  146. {
  147. get
  148. {
  149. return EnsureIdentifier();
  150. }
  151. }
  152. /// <summary>
  153. /// Gets the value that indicates whether current selector in multiple mode displays some data or whether the dropdown contains some data.
  154. /// </summary>
  155. public override bool HasData
  156. {
  157. get
  158. {
  159. // Ensure the data
  160. if (!StopProcessing)
  161. {
  162. Reload(false);
  163. }
  164. return ValidationHelper.GetBoolean(ViewState["HasData"], false);
  165. }
  166. protected set
  167. {
  168. ViewState["HasData"] = value;
  169. }
  170. }
  171. /// <summary>
  172. /// Zero rows text.
  173. /// </summary>
  174. public string ZeroRowsText
  175. {
  176. get
  177. {
  178. return ValidationHelper.GetString(ViewState["ZeroRowsText"], null);
  179. }
  180. set
  181. {
  182. ViewState["ZeroRowsText"] = value;
  183. }
  184. }
  185. /// <summary>
  186. /// Name of the edit window.
  187. /// </summary>
  188. public string EditWindowName
  189. {
  190. get
  191. {
  192. return mEditWindowName;
  193. }
  194. set
  195. {
  196. mEditWindowName = value;
  197. }
  198. }
  199. /// <summary>
  200. /// Gets or sets the width of modal dialog window used for editing.
  201. /// </summary>
  202. public int EditDialogWindowWidth
  203. {
  204. get
  205. {
  206. return mEditDialogWindowWidth;
  207. }
  208. set
  209. {
  210. mEditDialogWindowWidth = value;
  211. }
  212. }
  213. /// <summary>
  214. /// Gets or sets the height of modal dialog window used for editing.
  215. /// </summary>
  216. public int EditDialogWindowHeight
  217. {
  218. get
  219. {
  220. return mEditDialogWindowHeight;
  221. }
  222. set
  223. {
  224. mEditDialogWindowHeight = value;
  225. }
  226. }
  227. /// <summary>
  228. /// Value of the "(all)" DDL record, -1 by default.
  229. /// </summary>
  230. public string AllRecordValue
  231. {
  232. get
  233. {
  234. return ValidationHelper.GetString(ViewState["AllRecordValue"], US_ALL_RECORDS.ToString());
  235. }
  236. set
  237. {
  238. ViewState["AllRecordValue"] = value;
  239. }
  240. }
  241. /// <summary>
  242. /// Value of the "(none)" DDL record, 0 by default.
  243. /// </summary>
  244. public string NoneRecordValue
  245. {
  246. get
  247. {
  248. return ValidationHelper.GetString(ViewState["NoneRecordValue"], US_NONE_RECORD.ToString());
  249. }
  250. set
  251. {
  252. ViewState["NoneRecordValue"] = value;
  253. }
  254. }
  255. /// <summary>
  256. /// Gets or sets field value.
  257. /// </summary>
  258. public override object Value
  259. {
  260. get
  261. {
  262. return GetValue();
  263. }
  264. set
  265. {
  266. SetValue(value);
  267. }
  268. }
  269. /// <summary>
  270. /// Gets the display name of the value item. Returns null if display name is not available.
  271. /// </summary>
  272. public override string ValueDisplayName
  273. {
  274. get
  275. {
  276. return GetValueDisplayName();
  277. }
  278. }
  279. /// <summary>
  280. /// Gets or sets if control is enabled.
  281. /// </summary>
  282. public override bool Enabled
  283. {
  284. get
  285. {
  286. return ValidationHelper.GetBoolean(ViewState["Enabled"], true);
  287. }
  288. set
  289. {
  290. ViewState["Enabled"] = value;
  291. SetEnabled();
  292. }
  293. }
  294. /// <summary>
  295. /// Sets a value indicating whether the New button should be enabled.
  296. /// </summary>
  297. public bool ButtonNewEnabled
  298. {
  299. set
  300. {
  301. mButtonNewEnabled = value;
  302. }
  303. }
  304. /// <summary>
  305. /// Sets a value indicating whether the Edit button should be enabled.
  306. /// </summary>
  307. public bool ButtonEditEnabled
  308. {
  309. set
  310. {
  311. mButtonEditEnabled = value;
  312. }
  313. }
  314. /// <summary>
  315. /// Sets a value indicating whether the Remove button should be enabled.
  316. /// </summary>
  317. public bool ButtonRemoveEnabled
  318. {
  319. set
  320. {
  321. mButtonRemoveEnabled = value;
  322. }
  323. }
  324. /// <summary>
  325. /// Indicates if UniSelector value was set.
  326. /// </summary>
  327. public new bool HasValue
  328. {
  329. get
  330. {
  331. return ValidationHelper.GetBoolean(ViewState["HasValue"], false);
  332. }
  333. }
  334. /// <summary>
  335. /// Gets or sets the value that indicates whether the UniSelector should apply WhereCondition for the selected value (default: false). This does not affect the modal dialog.
  336. /// </summary>
  337. public bool ApplyValueRestrictions
  338. {
  339. get
  340. {
  341. return ValidationHelper.GetBoolean(ViewState["ApplyValueRestrictions"], true);
  342. }
  343. set
  344. {
  345. ViewState["ApplyValueRestrictions"] = value;
  346. }
  347. }
  348. /// <summary>
  349. /// Sets minimum priority for which items will be shown.
  350. /// </summary>
  351. public int? MinimumPriority
  352. {
  353. get;
  354. set;
  355. }
  356. /// <summary>
  357. /// Defines whether to prioritize items or not.
  358. /// </summary>
  359. public bool PrioritizeItems
  360. {
  361. get;
  362. set;
  363. }
  364. /// <summary>
  365. /// Dictionary of css classes of prioritized items.
  366. /// </summary>
  367. public Dictionary<int, string> PriorityStyles
  368. {
  369. get
  370. {
  371. return mPriorityStyles;
  372. }
  373. }
  374. /// <summary>
  375. /// Gets or sets site name. If set, only objects which belong to specified site are retrieved (if the object has SiteID column). If null or empty, all objects are retrieved.
  376. /// Use #currentsite for CurrentSite and #global for global objects.
  377. /// </summary>
  378. public string ObjectSiteName
  379. {
  380. get
  381. {
  382. return ValidationHelper.GetString(GetValue("ObjectSiteName"), null);
  383. }
  384. set
  385. {
  386. SetValue("ObjectSiteName", value);
  387. }
  388. }
  389. #endregion
  390. #region "Controls properties"
  391. /// <summary>
  392. /// Gets the single select drop down field.
  393. /// </summary>
  394. public DropDownList DropDownSingleSelect
  395. {
  396. get
  397. {
  398. return drpSingleSelect;
  399. }
  400. }
  401. /// <summary>
  402. /// Drop down list selection edit button.
  403. /// </summary>
  404. public UniButton ButtonDropDownEdit
  405. {
  406. get
  407. {
  408. return btnDropEdit;
  409. }
  410. }
  411. /// <summary>
  412. /// Gets the Select button control.
  413. /// </summary>
  414. public UniButton ButtonSelect
  415. {
  416. get
  417. {
  418. return btnSelect;
  419. }
  420. }
  421. /// <summary>
  422. /// Gets the Clear button control.
  423. /// </summary>
  424. public UniButton ButtonClear
  425. {
  426. get
  427. {
  428. return btnClear;
  429. }
  430. }
  431. /// <summary>
  432. /// Gets the Remove selected items button.
  433. /// </summary>
  434. public Button ButtonRemoveSelected
  435. {
  436. get
  437. {
  438. return btnRemoveSelected;
  439. }
  440. }
  441. /// <summary>
  442. /// Gets the Add items button control.
  443. /// </summary>
  444. public Button ButtonAddItems
  445. {
  446. get
  447. {
  448. return btnAddItems;
  449. }
  450. }
  451. /// <summary>
  452. /// Gets the text box selection control.
  453. /// </summary>
  454. public override CMSTextBox TextBoxSelect
  455. {
  456. get
  457. {
  458. return txtSingleSelect;
  459. }
  460. }
  461. /// <summary>
  462. /// Textbox selection edit button.
  463. /// </summary>
  464. public UniButton ButtonEdit
  465. {
  466. get
  467. {
  468. return btnEdit;
  469. }
  470. }
  471. /// <summary>
  472. /// Multiple selection grid.
  473. /// </summary>
  474. public UniGrid UniGrid
  475. {
  476. get
  477. {
  478. return uniGrid;
  479. }
  480. }
  481. /// <summary>
  482. /// Button selection control.
  483. /// </summary>
  484. public override Button DialogButton
  485. {
  486. get
  487. {
  488. return btnDialog;
  489. }
  490. }
  491. /// <summary>
  492. /// Label selection control.
  493. /// </summary>
  494. public override LocalizedLabel DialogLabel
  495. {
  496. get
  497. {
  498. return lblLinkDialog;
  499. }
  500. }
  501. /// <summary>
  502. /// Link selection control.
  503. /// </summary>
  504. public override HyperLink DialogLink
  505. {
  506. get
  507. {
  508. return lnkDialog;
  509. }
  510. }
  511. /// <summary>
  512. /// Link selection image control.
  513. /// </summary>
  514. public override Image DialogImage
  515. {
  516. get
  517. {
  518. return imgDialog;
  519. }
  520. }
  521. /// <summary>
  522. /// New item button.
  523. /// </summary>
  524. public UniButton ButtonDropDownNew
  525. {
  526. get
  527. {
  528. return btnDropNew;
  529. }
  530. }
  531. #endregion
  532. #region "Methods"
  533. private void SetEnabled()
  534. {
  535. btnClear.Enabled = Enabled;
  536. btnSelect.Enabled = Enabled;
  537. btnDialog.Enabled = Enabled;
  538. lnkDialog.Enabled = Enabled;
  539. drpSingleSelect.Enabled = Enabled;
  540. txtSingleSelect.Enabled = Enabled;
  541. btnRemoveSelected.Enabled = Enabled;
  542. btnAddItems.Enabled = Enabled;
  543. btnMenu.Enabled = Enabled;
  544. btnEdit.Enabled = Enabled;
  545. btnNew.Enabled = Enabled;
  546. btnDropNew.Enabled = Enabled;
  547. btnDropEdit.Enabled = Enabled;
  548. }
  549. /// <summary>
  550. /// Gets the display name of the selected value
  551. /// </summary>
  552. private string GetValueDisplayName()
  553. {
  554. switch (SelectionMode)
  555. {
  556. case SelectionModeEnum.SingleDropDownList:
  557. {
  558. // For dropdown, return the selected text
  559. if (drpSingleSelect.SelectedIndex >= 0)
  560. {
  561. return drpSingleSelect.Items[drpSingleSelect.SelectedIndex].Text;
  562. }
  563. else
  564. {
  565. return drpSingleSelect.Text;
  566. }
  567. }
  568. case SelectionModeEnum.SingleTextBox:
  569. case SelectionModeEnum.MultipleButton:
  570. case SelectionModeEnum.Multiple:
  571. case SelectionModeEnum.MultipleTextBox:
  572. case SelectionModeEnum.SingleButton:
  573. // Other types of selection - Get through the data items
  574. return GetDisplayName(Value);
  575. }
  576. return null;
  577. }
  578. /// <summary>
  579. /// Ensures the unique control identifier
  580. /// </summary>
  581. private string EnsureIdentifier()
  582. {
  583. string identifier = hdnIdentifier.Value;
  584. if (string.IsNullOrEmpty(identifier))
  585. {
  586. identifier = Request.Form[hdnIdentifier.UniqueID];
  587. if (string.IsNullOrEmpty(identifier))
  588. {
  589. identifier = Guid.NewGuid().ToString();
  590. }
  591. hdnIdentifier.Value = identifier;
  592. }
  593. return identifier;
  594. }
  595. /// <summary>
  596. /// Sets the value to the selector
  597. /// </summary>
  598. /// <param name="value">New value</param>
  599. private void SetValue(object value)
  600. {
  601. // Reset the control if the value is null
  602. if (value == null)
  603. {
  604. hdnDialogSelect.Value = String.Empty;
  605. txtSingleSelect.Text = String.Empty;
  606. hiddenField.Value = String.Empty;
  607. drpSingleSelect.SelectedIndex = -1;
  608. ViewState["HasValue"] = false;
  609. return;
  610. }
  611. switch (SelectionMode)
  612. {
  613. // Dropdown mode
  614. case SelectionModeEnum.SingleDropDownList:
  615. hdnDialogSelect.Value = ValidationHelper.GetString(value, "");
  616. if (drpSingleSelect.Items.FindByValue(hdnDialogSelect.Value) != null)
  617. {
  618. drpSingleSelect.SelectedValue = hdnDialogSelect.Value;
  619. }
  620. break;
  621. // Textbox mode
  622. case SelectionModeEnum.SingleTextBox:
  623. case SelectionModeEnum.MultipleTextBox:
  624. string text = ValidationHelper.GetString(value, String.Empty).Trim(ValuesSeparator.ToCharArray());
  625. if (AllowEditTextBox)
  626. {
  627. txtSingleSelect.Text = text;
  628. }
  629. hiddenField.Value = String.Format(";{0};", text);
  630. break;
  631. // Other modes
  632. default:
  633. hiddenField.Value = ";" + ValidationHelper.GetString(value, "").Trim(ValuesSeparator.ToCharArray()) + ";";
  634. break;
  635. }
  636. ViewState["HasValue"] = true;
  637. }
  638. /// <summary>
  639. /// Gets the current value of the selector
  640. /// </summary>
  641. private object GetValue()
  642. {
  643. switch (SelectionMode)
  644. {
  645. // Dropdown mode
  646. case SelectionModeEnum.SingleDropDownList:
  647. if (!String.IsNullOrEmpty(hdnDialogSelect.Value))
  648. {
  649. return hdnDialogSelect.Value;
  650. }
  651. else
  652. {
  653. return drpSingleSelect.SelectedValue;
  654. }
  655. // Textbox mode
  656. case SelectionModeEnum.SingleTextBox:
  657. case SelectionModeEnum.MultipleTextBox:
  658. if (AllowEditTextBox)
  659. {
  660. return txtSingleSelect.Text.Trim(ValuesSeparator.ToCharArray());
  661. }
  662. else
  663. {
  664. return hiddenField.Value.Trim(ValuesSeparator.ToCharArray());
  665. }
  666. // Other modes
  667. default:
  668. return hiddenField.Value.Trim(ValuesSeparator.ToCharArray());
  669. }
  670. }
  671. /// <summary>
  672. /// Returns true if user control is valid.
  673. /// </summary>
  674. public override bool IsValid()
  675. {
  676. return true;
  677. }
  678. protected override void LoadViewState(object savedState)
  679. {
  680. base.LoadViewState(savedState);
  681. // Do not overwrite value if ViewState doesn't contain value for current control (e.g. disabled control)
  682. if (Request.Form.AllKeys.Contains(hdnIdentifier.UniqueID))
  683. {
  684. // Get values from form if the control is loaded dynamically
  685. hdnIdentifier.Value = Request.Form[hdnIdentifier.UniqueID];
  686. }
  687. if (Request.Form.AllKeys.Contains(hiddenField.UniqueID))
  688. {
  689. hiddenField.Value = Request.Form[hiddenField.UniqueID];
  690. }
  691. }
  692. protected void Page_Load(object sender, EventArgs e)
  693. {
  694. if (RequestHelper.IsCallback())
  695. {
  696. StopProcessing = true;
  697. return;
  698. }
  699. // Register script for pendingCallbacks repair
  700. ScriptHelper.FixPendingCallbacks(Page);
  701. ScriptHelper.RegisterWOpenerScript(Page);
  702. checkBoxClass = Guid.NewGuid().ToString().Replace("-", "");
  703. // Bound events
  704. drpSingleSelect.SelectedIndexChanged += drpSingleSelect_SelectedIndexChanged;
  705. uniGrid.OnExternalDataBound += uniGrid_OnExternalDataBound;
  706. uniGrid.OnPageChanged += uniGrid_OnPageChanged;
  707. uniGrid.IsLiveSite = IsLiveSite;
  708. uniGrid.Pager.DefaultPageSize = 10;
  709. btnClear.Click += btnClear_Click;
  710. // If control is enabled, then display content
  711. if (!StopProcessing && (SelectionMode == SelectionModeEnum.Multiple))
  712. {
  713. if (!RequestHelper.CausedPostback(btnRemoveSelected, this, uniGrid.Pager.UniPager))
  714. {
  715. Reload(false);
  716. }
  717. }
  718. }
  719. /// <summary>
  720. /// Change header title for multiple selection.
  721. /// </summary>
  722. protected override void OnPreRender(EventArgs e)
  723. {
  724. if (StopProcessing)
  725. {
  726. return;
  727. }
  728. // If control is enabled, then display content
  729. if ((SelectionMode != SelectionModeEnum.Multiple) || !mLoaded)
  730. {
  731. Reload(false);
  732. }
  733. if (registerScripts)
  734. {
  735. RegisterScripts();
  736. }
  737. // Display two columns when in multiple selection
  738. if ((SelectionMode == SelectionModeEnum.Multiple) && (uniGrid.GridView.HeaderRow != null))
  739. {
  740. CheckBox chkAll = new CheckBox();
  741. chkAll.ID = "chkAll";
  742. chkAll.ToolTip = GetString("General.CheckAll");
  743. chkAll.InputAttributes.Add("onclick", "US_SelectAllItems('" + ClientID + "', '" + ValuesSeparator + "', this, 'chk" + checkBoxClass + "')");
  744. chkAll.Enabled = Enabled;
  745. uniGrid.GridView.HeaderRow.Cells[0].Controls.Clear();
  746. uniGrid.GridView.HeaderRow.Cells[0].Controls.Add(chkAll);
  747. uniGrid.GridView.Columns[0].ItemStyle.CssClass = "UnigridSelection";
  748. if (DynamicColumnName)
  749. {
  750. uniGrid.GridView.HeaderRow.Cells[1].Text = GetString(ResourcePrefix + ".itemname|general.itemname");
  751. }
  752. }
  753. lblStatus.Visible = !String.IsNullOrEmpty(lblStatus.Text);
  754. // If the page was not changed, deselect all
  755. if (!mPageChanged)
  756. {
  757. hiddenSelected.Value = "";
  758. }
  759. // Always reset the new value from dialog
  760. hdnDialogSelect.Value = "";
  761. InitializeControlEnvelope();
  762. // Enable/disable buttons when manually set
  763. SetButtonsEnabled();
  764. base.OnPreRender(e);
  765. }
  766. /// <summary>
  767. /// Initializes control envelope used in form controls definition.
  768. /// </summary>
  769. private void InitializeControlEnvelope()
  770. {
  771. if (!String.IsNullOrEmpty(CssClass))
  772. {
  773. if (!String.IsNullOrEmpty(ControlStyle))
  774. {
  775. ltlContentBefore.Text = String.Format("<div class=\"{0}\" style=\"{1}\" >", CssClass, ControlStyle);
  776. ltlContentAfter.Text = "</div>";
  777. }
  778. else
  779. {
  780. ltlContentBefore.Text = String.Format("<div class=\"{0}\" >", CssClass);
  781. ltlContentAfter.Text = "</div>";
  782. }
  783. }
  784. else
  785. {
  786. if (!String.IsNullOrEmpty(ControlStyle))
  787. {
  788. ltlContentBefore.Text = String.Format("<div style=\"{0}\" >", ControlStyle);
  789. ltlContentAfter.Text = "</div>";
  790. }
  791. else
  792. {
  793. ltlContentBefore.Visible = false;
  794. ltlContentAfter.Visible = false;
  795. }
  796. }
  797. }
  798. protected override void Render(HtmlTextWriter writer)
  799. {
  800. if (StopProcessing)
  801. {
  802. return;
  803. }
  804. // Render starting tag of wrapping element
  805. switch (SelectionMode)
  806. {
  807. case SelectionModeEnum.SingleButton:
  808. case SelectionModeEnum.SingleDropDownList:
  809. case SelectionModeEnum.SingleTextBox:
  810. writer.Write("<span id=\"" + ClientID + "\">");
  811. break;
  812. case SelectionModeEnum.Multiple:
  813. case SelectionModeEnum.MultipleButton:
  814. case SelectionModeEnum.MultipleTextBox:
  815. writer.Write("<div id=\"" + ClientID + "\">");
  816. break;
  817. }
  818. // Render child controls
  819. RenderChildren(writer);
  820. // Render ending tag of wrapping element
  821. switch (SelectionMode)
  822. {
  823. case SelectionModeEnum.SingleButton:
  824. case SelectionModeEnum.SingleDropDownList:
  825. case SelectionModeEnum.SingleTextBox:
  826. writer.Write("</span>");
  827. break;
  828. case SelectionModeEnum.Multiple:
  829. case SelectionModeEnum.MultipleButton:
  830. case SelectionModeEnum.MultipleTextBox:
  831. writer.Write("</div>");
  832. break;
  833. }
  834. }
  835. /// <summary>
  836. /// Reloads all controls.
  837. /// </summary>
  838. /// <param name="forceReload">Indicates if data should be loaded from DB</param>
  839. public void Reload(bool forceReload)
  840. {
  841. if (!mLoaded || forceReload)
  842. {
  843. LoadObjects(forceReload);
  844. if (!StopProcessing)
  845. {
  846. SetupControls();
  847. registerScripts = true;
  848. ReloadData(forceReload);
  849. }
  850. mLoaded = true;
  851. }
  852. }
  853. /// <summary>
  854. /// Displays data according to selection mode.
  855. /// </summary>
  856. private void ReloadData(bool forceReload)
  857. {
  858. // Check that object type is not empty
  859. if (Object != null)
  860. {
  861. // Display form control content according to selection mode
  862. switch (SelectionMode)
  863. {
  864. case SelectionModeEnum.SingleTextBox:
  865. DisplayTextBox();
  866. break;
  867. case SelectionModeEnum.SingleDropDownList:
  868. DisplayDropDownList(forceReload);
  869. break;
  870. case SelectionModeEnum.Multiple:
  871. DisplayMultiple(forceReload);
  872. break;
  873. case SelectionModeEnum.MultipleTextBox:
  874. DisplayMultipleTextBox();
  875. break;
  876. case SelectionModeEnum.SingleButton:
  877. case SelectionModeEnum.MultipleButton:
  878. DisplayButton();
  879. break;
  880. }
  881. }
  882. }
  883. /// <summary>
  884. /// Setups controls.
  885. /// </summary>
  886. private void SetupControls()
  887. {
  888. SetEnabled();
  889. // Add resource strings
  890. bool useImages = UseImageButtons;
  891. if (useImages)
  892. {
  893. btnClear.ImageUrl = GetImagePath("Design/Controls/UniGrid/Actions/delete.png");
  894. btnClear.ImageAltText = GetString(ResourcePrefix + ".clear|general.clear");
  895. btnSelect.ImageUrl = GetImagePath("Design/Controls/UniGrid/Actions/select.png");
  896. btnSelect.ImageAltText = GetString(ResourcePrefix + ".select|general.select");
  897. txtSingleSelect.CssClass = "TextBoxField";
  898. drpSingleSelect.CssClass = "DropDownField";
  899. }
  900. else
  901. {
  902. btnClear.ResourceString = ResourcePrefix + ".clear|general.clear";
  903. btnClear.ShowAsButton = true;
  904. lblClear.ResourceString = ResourcePrefix + ".clear|general.clear";
  905. btnSelect.ResourceString = ResourcePrefix + ".select|general.select";
  906. btnSelect.ShowAsButton = true;
  907. lblSelect.ResourceString = ResourcePrefix + ".select|general.select";
  908. }
  909. btnDialog.ResourceString = ResourcePrefix + ".select|general.select";
  910. lblDialog.ResourceString = ResourcePrefix + ".select|general.select";
  911. if (string.IsNullOrEmpty(lblLinkDialog.ResourceString))
  912. {
  913. lblLinkDialog.ResourceString = ResourcePrefix + ".select|general.select";
  914. }
  915. lblSingleSelectTxt.ResourceString = ResourcePrefix + ".selectitem|general.selectitem";
  916. lblSingleSelectDrp.ResourceString = ResourcePrefix + ".selectitem|general.selectitem";
  917. // Add event handlers
  918. string selScript = "US_SelectionDialog_" + ClientID + "(); return false;";
  919. switch (SelectionMode)
  920. {
  921. // Dropdownlist mode
  922. case SelectionModeEnum.SingleDropDownList:
  923. {
  924. if (!String.IsNullOrEmpty(EditItemPageUrl))
  925. {
  926. btnDropEdit.Visible = true;
  927. if (useImages)
  928. {
  929. btnDropEdit.ImageUrl = GetImagePath("Design/Controls/UniGrid/Actions/edit.png");
  930. btnDropEdit.ImageAltText = GetString(ResourcePrefix + ".edit|general.edit");
  931. }
  932. else
  933. {
  934. btnDropEdit.ResourceString = ResourcePrefix + ".edit|general.edit";
  935. btnDropEdit.ShowAsButton = true;
  936. }
  937. btnDropEdit.ButtonControl.RenderScript = true;
  938. lblDropEdit.Visible = true;
  939. lblDropEdit.ResourceString = ResourcePrefix + ".edit|general.edit";
  940. btnDropEdit.OnClientClick = "US_EditItem_" + ClientID + "(GetVal('" + drpSingleSelect.ClientID + "')); return false;";
  941. }
  942. // New button
  943. if (!String.IsNullOrEmpty(NewItemPageUrl))
  944. {
  945. btnDropNew.Visible = true;
  946. if (useImages)
  947. {
  948. btnDropNew.ImageUrl = GetImagePath("Design/Controls/UniGrid/Actions/new.png");
  949. btnDropNew.ImageAltText = GetString(ResourcePrefix + ".new|general.new");
  950. }
  951. else
  952. {
  953. btnDropNew.ResourceString = ResourcePrefix + ".new|general.new";
  954. btnDropNew.ShowAsButton = true;
  955. }
  956. lblDropNew.Visible = true;
  957. lblDropNew.ResourceString = ResourcePrefix + ".new|general.new";
  958. btnDropNew.OnClientClick = "US_NewItem_" + ClientID + "(GetVal('" + drpSingleSelect.ClientID + "')); return false;";
  959. }
  960. }
  961. break;
  962. // Multiple selection mode
  963. case SelectionModeEnum.Multiple:
  964. {
  965. btnRemoveSelected.ResourceString = ResourcePrefix + ".removeselected|general.removeselected";
  966. lblRemoveSelected.ResourceString = ResourcePrefix + ".removeselected|general.removeselected";
  967. btnAddItems.ResourceString = ResourcePrefix + ".additems|general.additems";
  968. lblAddItems.ResourceString = ResourcePrefix + ".additems|general.additems";
  969. string confirmation = RemoveConfirmation;
  970. if (confirmation == null)
  971. {
  972. confirmation = GetString("general.confirmremove");
  973. }
  974. if (!String.IsNullOrEmpty(confirmation))
  975. {
  976. btnRemoveSelected.OnClientClick = "return confirm(" + ScriptHelper.GetString(confirmation) + ")";
  977. }
  978. btnAddItems.OnClientClick = selScript;
  979. btnMenu.Parameter = ScriptHelper.GetString(ClientID);
  980. btnMenu.MenuControlPath = "~/CMSAdminControls/UI/UniSelector/Controls/SelectorMenu.ascx";
  981. btnMenu.IsLiveSite = IsLiveSite;
  982. }
  983. break;
  984. // Button mode
  985. case SelectionModeEnum.SingleButton:
  986. case SelectionModeEnum.MultipleButton:
  987. // Setup button
  988. if (ButtonImage == null)
  989. {
  990. btnDialog.OnClientClick = selScript;
  991. }
  992. else
  993. {
  994. if (Enabled)
  995. {
  996. lnkDialog.Attributes.Add("onclick", selScript);
  997. }
  998. else
  999. {
  1000. lnkDialog.Attributes.Remove("onclick");
  1001. }
  1002. lnkDialog.NavigateUrl = "#";
  1003. if (ButtonImage != "")
  1004. {
  1005. imgDialog.ImageUrl = ButtonImage;
  1006. imgDialog.AlternateText = GetString(ResourcePrefix + ".select|general.select");
  1007. imgDialog.ToolTip = GetString(ResourcePrefix + ".select|general.select");
  1008. }
  1009. else
  1010. {
  1011. imgDialog.Visible = false;
  1012. }
  1013. }
  1014. break;
  1015. // Single textbox mode
  1016. case SelectionModeEnum.SingleTextBox:
  1017. {
  1018. // Select button
  1019. if (AllowEditTextBox)
  1020. {
  1021. btnClear.OnClientClick = string.Format("SetVal('{0}', ''); return false;", txtSingleSelect.ClientID);
  1022. btnSelect.OnClientClick = "US_SelectionDialog_" + ClientID + "('$|' + GetVal('" + txtSingleSelect.ClientID + "')); return false;";
  1023. }
  1024. else
  1025. {
  1026. btnSelect.OnClientClick = selScript;
  1027. }
  1028. // Edit button
  1029. if (!String.IsNullOrEmpty(EditItemPageUrl))
  1030. {
  1031. btnEdit.Visible = true;
  1032. if (useImages)
  1033. {
  1034. btnEdit.ImageUrl = GetImagePath("Design/Controls/UniGrid/Actions/edit.png");
  1035. btnEdit.ImageAltText = GetString(ResourcePrefix + ".edit|general.edit");
  1036. }
  1037. else
  1038. {
  1039. btnEdit.ResourceString = ResourcePrefix + ".edit|general.edit";
  1040. btnEdit.ShowAsButton = true;
  1041. }
  1042. lblEdit.Visible = true;
  1043. lblEdit.ResourceString = ResourcePrefix + ".edit|general.edit";
  1044. if (AllowEditTextBox)
  1045. {
  1046. btnEdit.OnClientClick = "US_EditItem_" + ClientID + "(GetVal('" + txtSingleSelect.ClientID + "')); return false;";
  1047. }
  1048. else
  1049. {
  1050. btnEdit.OnClientClick = "US_EditItem_" + ClientID + "(GetVal('" + hiddenField.ClientID + "')); return false;";
  1051. }
  1052. }
  1053. // New button
  1054. if (!String.IsNullOrEmpty(NewItemPageUrl))
  1055. {
  1056. btnNew.Visible = true;
  1057. if (useImages)
  1058. {
  1059. btnNew.ImageUrl = GetImagePath("Design/Controls/UniGrid/Actions/new.png");
  1060. btnNew.ImageAltText = GetString(ResourcePrefix + ".new|general.new");
  1061. }
  1062. else
  1063. {
  1064. btnNew.ResourceString = ResourcePrefix + ".new|general.new";
  1065. btnNew.ShowAsButton = true;
  1066. }
  1067. lblNew.Visible = true;
  1068. lblNew.ResourceString = ResourcePrefix + ".new|general.new";
  1069. if (AllowEditTextBox)
  1070. {
  1071. btnNew.OnClientClick = "US_NewItem_" + ClientID + "(GetVal('" + txtSingleSelect.ClientID + "')); return false;";
  1072. }
  1073. else
  1074. {
  1075. btnNew.OnClientClick = "US_NewItem_" + ClientID + "(GetVal('" + hiddenField.ClientID + "')); return false;";
  1076. }
  1077. }
  1078. }
  1079. break;
  1080. // Multiple textbox
  1081. case SelectionModeEnum.MultipleTextBox:
  1082. // Select button
  1083. if (AllowEditTextBox)
  1084. {
  1085. btnClear.OnClientClick = string.Format("SetVal('{0}', ''); return false;", txtSingleSelect.ClientID);
  1086. btnSelect.OnClientClick = "US_SelectionDialog_" + ClientID + "('$|' + GetVal('" + txtSingleSelect.ClientID + "')); return false;";
  1087. }
  1088. else
  1089. {
  1090. btnSelect.OnClientClick = selScript;
  1091. }
  1092. break;
  1093. default:
  1094. btnSelect.OnClientClick = selScript;
  1095. break;
  1096. }
  1097. }
  1098. /// <summary>
  1099. /// Loads objects from DB and stores it to variables.
  1100. /// </summary>
  1101. private void LoadObjects(bool forceReload)
  1102. {
  1103. if (Object != null)
  1104. {
  1105. // Set return column name
  1106. if (String.IsNullOrEmpty(ReturnColumnName))
  1107. {
  1108. ReturnColumnName = Object.IDColumn;
  1109. }
  1110. // Open selection dialog depending if UniSelector is on live site
  1111. string url = null;
  1112. if (IsLiveSite)
  1113. {
  1114. url = "~/CMSAdminControls/UI/UniSelector/LiveSelectionDialog.aspx";
  1115. }
  1116. else
  1117. {
  1118. url = "~/CMSAdminControls/UI/UniSelector/SelectionDialog.aspx";
  1119. }
  1120. if (!String.IsNullOrEmpty(SelectItemPageUrl))
  1121. {
  1122. url = SelectItemPageUrl;
  1123. }
  1124. url += "?SelectionMode=" + SelectionMode + "&hidElem=" + hiddenField.ClientID + "&params=" + Server.UrlEncode(ScriptHelper.GetString(Identifier, false)) + "&clientId=" + ClientID + "&localize=" + (LocalizeItems ? 1 : 0) + AdditionalUrlParameters;
  1125. // Create modal dialogs and datasets according to selection mode
  1126. switch (SelectionMode)
  1127. {
  1128. // Single text box selection mode
  1129. case SelectionModeEnum.SingleTextBox:
  1130. url += "&txtElem=" + txtSingleSelect.ClientID;
  1131. break;
  1132. // Single drop down list selection mode
  1133. case SelectionModeEnum.SingleDropDownList:
  1134. if (drpSingleSelect.Items.Count == 0)
  1135. {
  1136. forceReload = true;
  1137. }
  1138. result = GetResultSet(null, MaxDisplayedTotalItems + 1, 0, forceReload);
  1139. url += "&selectElem=" + hdnDialogSelect.ClientID;
  1140. break;
  1141. // Multiple selection mode
  1142. case SelectionModeEnum.Multiple:
  1143. {
  1144. uniGrid.GridName = GridName;
  1145. uniGrid.LoadGridDefinition();
  1146. // Set custom page according to settings to restrict size of data
  1147. if (ItemsPerPage > 0)
  1148. {
  1149. uniGrid.Pager.DefaultPageSize = ItemsPerPage;
  1150. }
  1151. // Ensure new current page number
  1152. if (mNewCurrentPage > 0)
  1153. {
  1154. uniGrid.Pager.UniPager.CurrentPage = mNewCurrentPage;
  1155. }
  1156. int currentOffset = (uniGrid.Pager.CurrentPage - 1) * uniGrid.Pager.CurrentPageSize;
  1157. int totalRecords = 0;
  1158. // Display only selected items
  1159. string ids = hiddenField.Value;
  1160. result = GetResultSet(ids, 0, 0, forceReload, currentOffset, uniGrid.Pager.CurrentPageSize, ref totalRecords);
  1161. // If not first page and no data loaded load first page
  1162. if (DataHelper.DataSourceIsEmpty(result) && (currentOffset > 0))
  1163. {
  1164. // Set uni grid page to 1 and reload data
  1165. uniGrid.Pager.UniPager.CurrentPage = 1;
  1166. result = GetResultSet(ids, 0, 0, forceReload, 0, uniGrid.Pager.CurrentPageSize, ref totalRecords);
  1167. }
  1168. uniGrid.PagerForceNumberOfResults = totalRecords;
  1169. javaScript.Append("function US_RemoveAll_", ClientID, "(){ if (confirm(", ScriptHelper.GetString(GetString("general.confirmremoveall")), ")) {", Page.ClientScript.GetPostBackEventReference(this, "removeall"), "; return false; }} \n");
  1170. }
  1171. break;
  1172. // Multiple text box selection mode
  1173. case SelectionModeEnum.MultipleTextBox:
  1174. url += "&txtElem=" + txtSingleSelect.ClientID;
  1175. break;
  1176. // Button selection
  1177. case SelectionModeEnum.SingleButton:
  1178. case SelectionModeEnum.MultipleButton:
  1179. break;
  1180. default:
  1181. url = null;
  1182. result = null;
  1183. break;
  1184. }
  1185. // Selection dialog window
  1186. if (url != null)
  1187. {
  1188. // Add IsSiteManager parameter to handle edit and new window
  1189. url += IsSiteManager ? "&siteManager=true" : String.Empty;
  1190. // Add hash
  1191. string hash = ValidationHelper.GetHashString(url.Substring(url.IndexOfCSafe('?')));
  1192. url += "&hash=" + hash;
  1193. javaScript.Append("function US_SelectionDialog_", ClientID, "(values) { ", Page.ClientScript.GetCallbackEventReference(this, "values", "US_SelectionDialogReady_" + ClientID, "'" + ResolveUrl(url) + "'"), "; } \n");
  1194. }
  1195. // Create selection changed function
  1196. if (OnSelectionChangedAvailable())
  1197. {
  1198. javaScript.Append("function US_SelectionChanged_", ClientID, "() { ", Page.ClientScript.GetPostBackEventReference(this, "selectionchanged"), "; } \n");
  1199. }
  1200. // New item window
  1201. if (!String.IsNullOrEmpty(NewItemPageUrl))
  1202. {
  1203. string newUrl = URLHelper.AddParameterToUrl(NewItemPageUrl, "selectorId", ClientID) + AdditionalUrlParameters;
  1204. javaScript.Append("function US_NewItem_", ClientID, "(selectedItem) {{ var url = '", ResolveUrl(newUrl), "';modalDialog(url.replace(/##ITEMID##/i, selectedItem),'NewItem', ", EditDialogWindowWidth, ", ", EditDialogWindowHeight, "); }} \n");
  1205. }
  1206. // Edit item window
  1207. if (!String.IsNullOrEmpty(EditItemPageUrl))
  1208. {
  1209. string newUrl = URLHelper.AddParameterToUrl(EditItemPageUrl, "selectorId", ClientID) + AdditionalUrlParameters;
  1210. javaScript.Append(
  1211. @"
  1212. function US_EditItem_", ClientID, @"(selectedItem) {
  1213. if (selectedItem == '') {
  1214. alert(", ScriptHelper.GetString(GetString(ResourcePrefix + ".pleaseselectitem|general.pleaseselectitem")), @");
  1215. return false;
  1216. }
  1217. else if (selectedItem.indexOf('{%') >= 0) {
  1218. alert(", ScriptHelper.GetString(GetString(ResourcePrefix + ".cannoteditmacro|general.cannoteditmacro")), @");
  1219. return false;
  1220. }
  1221. var url = '", ResolveUrl(newUrl), @"';
  1222. modalDialog(url.replace(/##ITEMID##/i, selectedItem),'", EditWindowName, "', ", EditDialogWindowWidth, ", ", EditDialogWindowHeight, @");
  1223. }
  1224. "
  1225. );
  1226. }
  1227. string conf = "";
  1228. if (!String.IsNullOrEmpty(SelectionConfirmation))
  1229. {
  1230. conf = "if(!confirm(" + ScriptHelper.GetString(SelectionConfirmation) + ")) { return false; }";
  1231. }
  1232. javaScript.Append(
  1233. "function US_ReloadPage_", ClientID, "() { ", Page.ClientScript.GetPostBackEventReference(this, "reload"), "; return false; } \n",
  1234. "function US_SelectItems_", ClientID, "(items){ ", conf, " document.getElementById('", hiddenField.ClientID, "').value = items; ", Page.ClientScript.GetPostBackEventReference(this, "selectitems"), "; return false; } \n",
  1235. "function US_SelectNewValue_", ClientID, "(selValue){ document.getElementById('", hiddenSelected.ClientID, "').value = selValue; ", Page.ClientScript.GetPostBackEventReference(this, "selectnewvalue"), "; return false; }\n");
  1236. }
  1237. else
  1238. {
  1239. lblStatus.Text = "[UniSelector]: Object type '" + ObjectType + "' not found.";
  1240. StopProcessing = true;
  1241. }
  1242. }
  1243. /// <summary>
  1244. /// Sets the dialog parameters to the context.
  1245. /// </summary>
  1246. protected void SetDialogParameters(string values)
  1247. {
  1248. parameters["SelectionMode"] = SelectionMode;
  1249. parameters["ResourcePrefix"] = ResourcePrefix;
  1250. parameters["ObjectType"] = ObjectType;
  1251. parameters["ReturnColumnName"] = ReturnColumnName;
  1252. parameters["IconPath"] = IconPath;
  1253. parameters["AllowEmpty"] = AllowEmpty;
  1254. parameters["AllowDefault"] = AllowDefault;
  1255. parameters["AllowAll"] = AllowAll;
  1256. parameters["NoneRecordValue"] = NoneRecordValue;
  1257. parameters["AllRecordValue"] = AllRecordValue;
  1258. parameters["FilterControl"] = FilterControl;
  1259. parameters["UseDefaultNameFilter"] = UseDefaultNameFilter;
  1260. parameters["WhereCondition"] = WhereCondition;
  1261. parameters["OrderBy"] = OrderBy;
  1262. parameters["ItemsPerPage"] = ItemsPerPage;
  1263. parameters["EmptyReplacement"] = EmptyReplacement;
  1264. parameters["Values"] = ";" + values + ";";
  1265. parameters["DisplayNameFormat"] = DisplayNameFormat;
  1266. parameters["DialogGridName"] = DialogGridName;
  1267. parameters["AdditionalColumns"] = AdditionalColumns;
  1268. parameters["CallbackMethod"] = CallbackMethod;
  1269. parameters["AllowEditTextBox"] = AllowEditTextBox;
  1270. parameters["FireOnChanged"] = OnSelectionChangedAvailable();
  1271. parameters["DisabledItems"] = DisabledItems;
  1272. parameters["AddGlobalObjectSuffix"] = AddGlobalObjectSuffix;
  1273. parameters["AddGlobalObjectNamePrefix"] = AddGlobalObjectNamePrefix;
  1274. parameters["GlobalObjectSuffix"] = GlobalObjectSuffix;
  1275. parameters["RemoveMultipleCommas"] = RemoveMultipleCommas;
  1276. parameters["IsSiteManager"] = IsSiteManager;
  1277. parameters["FilterMode"] = GetValue("FilterMode");
  1278. parameters["AdditionalSearchColumns"] = AdditionalSearchColumns;
  1279. parameters["SiteWhereCondition"] = GetSiteWhereCondition();
  1280. WindowHelper.Add(Identifier, parameters);
  1281. }
  1282. /// <summary>
  1283. /// Displays single selection textbox.
  1284. /// </summary>
  1285. private void DisplayTextBox()
  1286. {
  1287. plcTextBoxSelect.Visible = true;
  1288. if (!AllowEmpty && !AllowDefault)
  1289. {
  1290. btnClear.Visible = false;
  1291. lblClear.Visible = false;
  1292. }
  1293. if (AllowEditTextBox)
  1294. {
  1295. // Load the selected value
  1296. txtSingleSelect.ReadOnly = false;
  1297. }
  1298. else
  1299. {
  1300. // Get the item
  1301. txtSingleSelect.Text = GetDisplayName(Value);
  1302. }
  1303. }
  1304. /// <summary>
  1305. /// Gets the item name for the given item ID (value)
  1306. /// </summary>
  1307. /// <param name="value">Item value</param>
  1308. private string GetDisplayName(object value)
  1309. {
  1310. string ids = ValidationHelper.GetString(Value, null);
  1311. if (!String.IsNullOrEmpty(ids))
  1312. {
  1313. // Load textbox with data
  1314. DataSet ds = GetResultSet(ids, 0, 0, true);
  1315. if (!DataHelper.DataSourceIsEmpty(ds))
  1316. {
  1317. // Build the list of names
  1318. List<string> names = new List<string>();
  1319. StringSafeDictionary<bool> usedValues = new StringSafeDictionary<bool>();
  1320. foreach (DataRow dr in ds.Tables[0].Rows)
  1321. {
  1322. string val = ValidationHelper.GetString(dr[ReturnColumnName], "");
  1323. if (!usedValues.Contains(val))
  1324. {
  1325. // Add the display name
  1326. string name = GetItemName(dr);
  1327. if (!String.IsNullOrEmpty(name))
  1328. {
  1329. names.Add(name);
  1330. }
  1331. usedValues[val] = true;
  1332. }
  1333. }
  1334. // Each name on single line
  1335. return names.Join("\n");
  1336. }
  1337. }
  1338. return "";
  1339. }
  1340. /// <summary>
  1341. /// Displays single selection drop down list.
  1342. /// </summary>
  1343. private void DisplayDropDownList(bool forceReload)
  1344. {
  1345. hiddenField.Visible = false;
  1346. plcDropdownSelect.Visible = true;
  1347. object selectedValue = Value;
  1348. if (!RequestHelper.IsPostBack() || forceReload || (drpSingleSelect.Items.Count == 0) || !String.IsNullOrEmpty(EnabledColumnName))
  1349. {
  1350. // Prepare controls and variables
  1351. drpSingleSelect.Items.Clear();
  1352. bool hasData = !DataHelper.DataSourceIsEmpty(result);
  1353. // Load data to drop-down list
  1354. if (hasData && (Object != null))
  1355. {
  1356. drpSingleSelect.Items.Clear();
  1357. bool maxExceeded = (result.Tables[0].Rows.Count > MaxDisplayedTotalItems);
  1358. // Populate the dropdownlist
  1359. int index = 0;
  1360. foreach (DataRow dr in result.Tables[0].Rows)
  1361. {
  1362. drpSingleSelect.Items.Add(NewListItem(dr));
  1363. if (maxExceeded && (++index >= MaxDisplayedItems))
  1364. {
  1365. break;
  1366. }
  1367. }
  1368. // Check if all items were displayed or if '(more items)' item should be added
  1369. if (maxExceeded)
  1370. {
  1371. drpSingleSelect.Items.Add(new ListItem(GetString(ResourcePrefix + ".moreitems|general.moreitems"), US_MORE_RECORDS.ToString()));
  1372. }
  1373. }
  1374. // Display special items
  1375. if ((SpecialFields != null) && (SpecialFields.Length > 0))
  1376. {
  1377. string text = null;
  1378. string value = null;
  1379. ListItem existing = null;
  1380. for (int i = 0; i < SpecialFields.Length / 2; i++)
  1381. {
  1382. text = SpecialFields[i, 0];
  1383. value = Specia

Large files files are truncated, but you can click here to view the full file