WebComboBox.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using FastReport.Dialog;
  2. using System.Text;
  3. using static FastReport.Web.Constants;
  4. namespace FastReport.Web
  5. {
  6. public partial class Dialog
  7. {
  8. private void ComboBoxChange(ComboBoxControl cb, int index)
  9. {
  10. cb.SelectedIndex = index;
  11. ControlFilterRefresh(cb);
  12. cb.OnSelectedIndexChanged(null);
  13. }
  14. private string GetComboBoxHtml(ComboBoxControl control)
  15. {
  16. if (control.Items.Count == 0)
  17. {
  18. control.FillData();
  19. ControlFilterRefresh(control);
  20. }
  21. else
  22. {
  23. if (control.SelectedIndex == -1)
  24. control.SelectedIndex = 0;
  25. control.SelectedItem = control.Items[control.SelectedIndex];
  26. control.Text = control.SelectedItem.ToString();
  27. }
  28. string id = GetControlID(control);
  29. string html = $"<select style=\"{GetComboBoxStyle(control)}\" name=\"{control.Name}\"" +
  30. $" onchange=\"{GetEvent(ONCHANGE, control, SILENT_RELOAD, $"document.getElementById('{id}').selectedIndex")}\"" +
  31. $" id=\"{id}\" {(control.Enabled ? "" : "disabled")}>{GetComboBoxItems(control)}</select>";
  32. control.FilterData();
  33. return html;
  34. }
  35. private string GetComboBoxItems(ComboBoxControl control)
  36. {
  37. StringBuilder sb = new StringBuilder();
  38. for (int i = 0; i < control.Items.Count; i++)
  39. {
  40. sb.AppendFormat("<option {0} value=\"{1}\">{2}</option>",
  41. i == control.SelectedIndex ? "selected" : "",
  42. control.Items[i],
  43. control.Items[i]);
  44. }
  45. return sb.ToString();
  46. }
  47. private string GetComboBoxStyle(ComboBoxControl control)
  48. {
  49. return GetStandardStyle(control);
  50. }
  51. }
  52. }