2 // System.Web.UI.DataBoundLiteralCOntrol.cs
5 // Duncan Mak (duncan@ximian.com)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 // (C) 2002 Ximian, Inc. (http://www.ximian.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.ComponentModel;
36 namespace System.Web.UI {
39 public sealed class DataBoundLiteralControl : Control
41 private string [] staticLiterals;
42 private string [] dataBoundLiterals;
44 public DataBoundLiteralControl (int staticLiteralsCount,
45 int dataBoundLiteralCount)
47 staticLiterals = new string [staticLiteralsCount];
48 dataBoundLiterals = new string [dataBoundLiteralCount];
54 StringBuilder text = new StringBuilder ();
55 int stLength = staticLiterals.Length;
56 int dbLength = dataBoundLiterals.Length;
57 int max = (stLength > dbLength) ? stLength : dbLength;
58 for (int i = 0; i < max; i++){
60 text.Append (staticLiterals [i]);
62 text.Append (dataBoundLiterals [i]);
65 return text.ToString ();
69 protected override ControlCollection CreateControlCollection ()
71 return new EmptyControlCollection (this);
74 protected override void LoadViewState (object savedState)
76 if (savedState != null) {
77 Array source = (Array) savedState;
78 if (source.Length == dataBoundLiterals.Length)
79 source.CopyTo (dataBoundLiterals, 0);
83 protected override void Render (HtmlTextWriter output)
88 protected override object SaveViewState ()
90 if (dataBoundLiterals.Length == 0)
92 return dataBoundLiterals;
95 public void SetDataBoundString (int index, string s)
97 dataBoundLiterals [index] = s;
100 public void SetStaticString (int index, string s)
102 staticLiterals [index] = s;