WebComboBox.cs 2.0 KB

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