DataBoundLiteralControl.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // System.Web.UI.DataBoundLiteralCOntrol.cs
  3. //
  4. // Authors:
  5. // Duncan Mak ([email protected])
  6. // Gonzalo Paniagua Javier ([email protected])
  7. //
  8. // (C) 2002 Ximian, Inc. (http://www.ximian.com)
  9. //
  10. using System;
  11. using System.ComponentModel;
  12. using System.Text;
  13. namespace System.Web.UI {
  14. [ToolboxItem(false)]
  15. public sealed class DataBoundLiteralControl : Control
  16. {
  17. private string [] staticLiterals;
  18. private string [] dataBoundLiterals;
  19. public DataBoundLiteralControl (int staticLiteralsCount,
  20. int dataBoundLiteralCount)
  21. {
  22. staticLiterals = new string [staticLiteralsCount];
  23. dataBoundLiterals = new string [dataBoundLiteralCount];
  24. PreventAutoID ();
  25. }
  26. public string Text {
  27. get {
  28. StringBuilder text = new StringBuilder ();
  29. int stLength = staticLiterals.Length;
  30. int dbLength = dataBoundLiterals.Length;
  31. int max = (stLength > dbLength) ? stLength : dbLength;
  32. for (int i = 0; i < max; i++){
  33. if (i < stLength)
  34. text.Append (staticLiterals [i]);
  35. if (i < dbLength)
  36. text.Append (dataBoundLiterals [i]);
  37. }
  38. return text.ToString ();
  39. }
  40. }
  41. protected override ControlCollection CreateControlCollection ()
  42. {
  43. return new EmptyControlCollection (this);
  44. }
  45. protected override void LoadViewState (object savedState)
  46. {
  47. if (savedState != null)
  48. dataBoundLiterals = (string []) savedState;
  49. }
  50. protected override void Render (HtmlTextWriter output)
  51. {
  52. output.Write (Text);
  53. }
  54. protected override object SaveViewState ()
  55. {
  56. if (dataBoundLiterals.Length == 0)
  57. return null;
  58. return dataBoundLiterals;
  59. }
  60. public void SetDataBoundString (int index, string s)
  61. {
  62. dataBoundLiterals [index] = s;
  63. }
  64. public void SetStaticString (int index, string s)
  65. {
  66. staticLiterals [index] = s;
  67. }
  68. }
  69. }