WebListBox.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 ListBoxChange(ListBoxControl cb, int index)
  11. {
  12. cb.SelectedIndex = index;
  13. ControlFilterRefresh(cb);
  14. cb.OnSelectedIndexChanged(null);
  15. }
  16. private string GetListBoxHtml(ListBoxControl 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}\" size=\"{3}\" onchange=\"{4}\" id=\"{5}\" {7}>{6}</select>",
  25. // class
  26. "",
  27. // style
  28. GetListBoxStyle(control),
  29. // name
  30. control.Name,
  31. // size
  32. control.Items.Count.ToString(),
  33. // onclick
  34. GetEvent("onchange", control, string.Format("document.getElementById('{0}').selectedIndex", id)),
  35. // title
  36. id,
  37. GetListBoxItems(control),//control.Text
  38. control.Enabled ? "" : "disabled"
  39. );
  40. control.FilterData();
  41. return html;
  42. }
  43. private string GetListBoxItems(ListBoxControl control)
  44. {
  45. StringBuilder sb = new StringBuilder();
  46. for (int i = 0; i < control.Items.Count; i++)
  47. {
  48. sb.AppendFormat("<option {0}>{1}</option>",
  49. i == control.SelectedIndex ? "selected" : "",
  50. control.Items[i]);
  51. }
  52. return sb.ToString();
  53. }
  54. private string GetListBoxStyle(ListBoxControl control)
  55. {
  56. return GetStandardStyle(control);
  57. }
  58. }
  59. }