本文整理汇总了C#中System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls方法的典型用法代码示例。如果您正苦于以下问题:C# CompositeDataBoundControl.CreateChildControls方法的具体用法?C# CompositeDataBoundControl.CreateChildControls怎么用?C# CompositeDataBoundControl.CreateChildControls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.WebControls.CompositeDataBoundControl
的用法示例。
在下文中一共展示了CompositeDataBoundControl.CreateChildControls方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Table
//引入命名空间
using System;
using System.Collections;
using System.Data.Common;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Samples.AspNet.CS
{
public class SimpleSpreadsheetControl : CompositeDataBoundControl
{
protected Table table = new Table();
public virtual TableRowCollection Rows
{
get
{
return table.Rows;
}
}
protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
{
int count = 0;
// If dataSource is not null, iterate through it and
// extract each element from it as a row, then
// create a SimpleSpreadsheetRow and add it to the
// rows collection.
if (dataSource != null)
{
SimpleSpreadsheetRow row;
IEnumerator e = dataSource.GetEnumerator();
while (e.MoveNext())
{
object datarow = e.Current;
row = new SimpleSpreadsheetRow(count, datarow);
this.Rows.Add(row);
++count;
}
Controls.Add(table);
}
return count;
}
}
//
//
public class SimpleSpreadsheetRow : TableRow, IDataItemContainer
{
private object data;
private int _itemIndex;
public SimpleSpreadsheetRow(int itemIndex, object o)
{
data = o;
_itemIndex = itemIndex;
}
public virtual object Data
{
get
{
return data;
}
}
object IDataItemContainer.DataItem
{
get
{
return Data;
}
}
int IDataItemContainer.DataItemIndex
{
get
{
return _itemIndex;
}
}
int IDataItemContainer.DisplayIndex
{
get
{
return _itemIndex;
}
}
protected override void RenderContents(HtmlTextWriter writer)
{
if (Data != null)
{
if (Data is System.Data.Common.DbDataRecord)
{
DbDataRecord temp = (DbDataRecord)Data;
for (int i = 0; i < temp.FieldCount; ++i)
{
writer.Write("<TD>");
writer.Write(temp.GetValue(i).ToString());
writer.Write("</TD>");
}
}
else
{
writer.Write("<TD>" + Data.ToString() + "</TD>");
}
}
else
{
writer.Write("<TD>This is a test</TD>");
}
}
}
}
开发者ID:.NET开发者,项目名称:System.Web.UI.WebControls,代码行数:118,代码来源:CompositeDataBoundControl.CreateChildControls