WebCheckedListBox.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using FastReport.Dialog;
  2. using System;
  3. using System.Text;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. namespace FastReport.Web
  8. {
  9. public partial class WebReport : WebControl, INamingContainer
  10. {
  11. private void CheckedListBoxChange(CheckedListBoxControl cb, string index)
  12. {
  13. int i = index.IndexOf("_");
  14. if (i != -1)
  15. {
  16. string item = index.Substring(0, i);
  17. string state = index.Substring(i + 1);
  18. int checkedIndex;
  19. if (Int32.TryParse(item, out checkedIndex))
  20. {
  21. cb.CheckedListBox.SetItemChecked(checkedIndex, state == "true");
  22. ControlFilterRefresh(cb);
  23. cb.OnSelectedIndexChanged(null);
  24. }
  25. }
  26. }
  27. private string GetCheckedListBoxHtml(CheckedListBoxControl control)
  28. {
  29. if (control.Items.Count == 0)
  30. {
  31. control.FillData();
  32. ControlFilterRefresh(control);
  33. }
  34. string id = Prop.ControlID + control.Name;
  35. string html = string.Format("<span class=\"{0}\" style=\"{1}\" name=\"{2}\" size=\"{3}\" id=\"{4}\">{5}</span>",
  36. // class
  37. "",
  38. // style
  39. GetCheckedListBoxStyle(control),
  40. // name
  41. control.Name,
  42. // size
  43. control.Items.Count.ToString(),
  44. // title
  45. id,
  46. GetCheckedListBoxItems(control)
  47. );
  48. control.FilterData();
  49. return html;
  50. }
  51. private string GetCheckedListBoxItems(CheckedListBoxControl control)
  52. {
  53. StringBuilder sb = new StringBuilder();
  54. string disabled = control.Enabled ? "" : "disabled";
  55. for (int i = 0; i < control.Items.Count; i++)
  56. {
  57. string id = Prop.ControlID + control.Name + i.ToString();
  58. sb.AppendFormat("<input {0} type=\"checkbox\" onchange=\"{1}\" id=\"{2}\" {4}/> {3}<br />",
  59. control.CheckedIndices.Contains(i) ? "checked" : "",
  60. // onchange
  61. GetEvent("onchange", control, i.ToString() + " + '_' + " + String.Format("document.getElementById('{0}').checked", id)),
  62. id,
  63. control.Items[i],
  64. disabled
  65. );
  66. }
  67. return sb.ToString();
  68. }
  69. private string GetCheckedListBoxStyle(CheckedListBoxControl control)
  70. {
  71. return string.Format("overflow-y:scroll;{0}", GetStandardStyle(control));
  72. }
  73. }
  74. }