DataBoundLiteralControl.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.Text;
  12. namespace System.Web.UI {
  13. public sealed class DataBoundLiteralControl : Control
  14. {
  15. private string [] staticLiterals;
  16. private string [] dataBoundLiterals;
  17. public DataBoundLiteralControl (int staticLiteralsCount,
  18. int dataBoundLiteralCount)
  19. {
  20. staticLiterals = new string [staticLiteralsCount];
  21. dataBoundLiterals = new string [dataBoundLiteralCount];
  22. PreventAutoID ();
  23. }
  24. public string Text {
  25. get {
  26. StringBuilder text = new StringBuilder ();
  27. int stLength = staticLiterals.Length;
  28. int dbLength = dataBoundLiterals.Length;
  29. int max = (stLength > dbLength) ? stLength : dbLength;
  30. for (int i = 0; i < max; i++){
  31. if (i < stLength)
  32. text.Append (staticLiterals [i]);
  33. if (i < dbLength)
  34. text.Append (dataBoundLiterals [i]);
  35. }
  36. return text.ToString ();
  37. }
  38. }
  39. protected override ControlCollection CreateControlCollection ()
  40. {
  41. return new EmptyControlCollection (this);
  42. }
  43. protected override void LoadViewState (object savedState)
  44. {
  45. if (savedState != null)
  46. dataBoundLiterals = (string []) savedState;
  47. }
  48. protected override void Render (HtmlTextWriter output)
  49. {
  50. output.Write (Text);
  51. }
  52. protected override object SaveViewState ()
  53. {
  54. if (dataBoundLiterals.Length == 0)
  55. return null;
  56. return dataBoundLiterals;
  57. }
  58. public void SetDataBoundString (int index, string s)
  59. {
  60. dataBoundLiterals [index] = s;
  61. }
  62. public void SetStaticString (int index, string s)
  63. {
  64. staticLiterals [index] = s;
  65. }
  66. }
  67. }