Files
mono/mcs/class/System.Web/System.Web.UI/DataBoundLiteralControl.cs
T
Gonzalo Paniagua Javier 9df48218d9 no need to allocate new array
svn path=/trunk/mcs/; revision=18433
2003-09-30 14:16:22 +00:00

86 lines
1.9 KiB
C#
Executable File

//
// System.Web.UI.DataBoundLiteralCOntrol.cs
//
// Authors:
// Duncan Mak ([email protected])
// Gonzalo Paniagua Javier ([email protected])
//
// (C) 2002 Ximian, Inc. (http://www.ximian.com)
//
using System;
using System.ComponentModel;
using System.Text;
namespace System.Web.UI {
[ToolboxItem(false)]
public sealed class DataBoundLiteralControl : Control
{
private string [] staticLiterals;
private string [] dataBoundLiterals;
public DataBoundLiteralControl (int staticLiteralsCount,
int dataBoundLiteralCount)
{
staticLiterals = new string [staticLiteralsCount];
dataBoundLiterals = new string [dataBoundLiteralCount];
PreventAutoID ();
}
public string Text {
get {
StringBuilder text = new StringBuilder ();
int stLength = staticLiterals.Length;
int dbLength = dataBoundLiterals.Length;
int max = (stLength > dbLength) ? stLength : dbLength;
for (int i = 0; i < max; i++){
if (i < stLength)
text.Append (staticLiterals [i]);
if (i < dbLength)
text.Append (dataBoundLiterals [i]);
}
return text.ToString ();
}
}
protected override ControlCollection CreateControlCollection ()
{
return new EmptyControlCollection (this);
}
protected override void LoadViewState (object savedState)
{
if (savedState != null) {
Array source = (Array) savedState;
if (source.Length == dataBoundLiterals.Length)
source.CopyTo (dataBoundLiterals, 0);
}
}
protected override void Render (HtmlTextWriter output)
{
output.Write (Text);
}
protected override object SaveViewState ()
{
if (dataBoundLiterals.Length == 0)
return null;
return dataBoundLiterals;
}
public void SetDataBoundString (int index, string s)
{
dataBoundLiterals [index] = s;
}
public void SetStaticString (int index, string s)
{
staticLiterals [index] = s;
}
}
}