本文整理汇总了C#中System.Web.UI.WebControls.WebParts.IWebPartRow接口的典型用法代码示例。如果您正苦于以下问题:C# IWebPartRow接口的具体用法?C# IWebPartRow怎么用?C# IWebPartRow使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。
IWebPartRow接口属于System.Web.UI.WebControls.WebParts命名空间,在下文中一共展示了IWebPartRow接口的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RowProviderWebPart
//引入命名空间
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Reflection;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace Samples.AspNet.CS.Controls
{
// This sample code creates a Web Parts control that acts as a provider
// of row data.
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class RowProviderWebPart : WebPart, IWebPartRow
{
private DataTable _table;
public RowProviderWebPart()
{
_table = new DataTable();
DataColumn col = new DataColumn();
col.DataType = typeof(string);
col.ColumnName = "Name";
_table.Columns.Add(col);
col = new DataColumn();
col.DataType = typeof(string);
col.ColumnName = "Address";
_table.Columns.Add(col);
col = new DataColumn();
col.DataType = typeof(int);
col.ColumnName = "ZIP Code";
_table.Columns.Add(col);
DataRow row = _table.NewRow();
row["Name"] = "John Q. Public";
row["Address"] = "123 Main Street";
row["ZIP Code"] = 98000;
_table.Rows.Add(row);
}
[ConnectionProvider("Row")]
public IWebPartRow GetConnectionInterface()
{
return new RowProviderWebPart();
}
public PropertyDescriptorCollection Schema
{
get
{
return TypeDescriptor.GetProperties(_table.DefaultView[0]);
}
}
public void GetRowData(RowCallback callback)
{
callback(_table.Rows);
}
} // RowProviderWebPart
// This sample code creates a Web Parts control that acts as a consumer
// of row data.
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class RowConsumerWebPart : WebPart
{
private IWebPartRow _provider;
private ICollection _tableData;
private void GetRowData(object rowData)
{
_tableData = (ICollection)rowData;
}
protected override void OnPreRender(EventArgs e)
{
if (_provider != null)
{
_provider.GetRowData(new RowCallback(GetRowData));
}
}
protected override void RenderContents(HtmlTextWriter writer)
{
if (_provider != null)
{
PropertyDescriptorCollection props = _provider.Schema;
int count = 0;
if (props != null && props.Count > 0 && _tableData != null)
{
foreach (PropertyDescriptor prop in props)
{
foreach (DataRow o in _tableData)
{
writer.Write(prop.DisplayName + ": " + o[count]);
writer.WriteBreak();
writer.WriteLine();
count = count + 1;
}
}
}
else
{
writer.Write("No data");
}
}
else
{
writer.Write("Not connected");
}
}
[ConnectionConsumer("Row")]
public void SetConnectionInterface(IWebPartRow provider)
{
_provider = provider;
}
} // RowConsumerWebPart
} // Samples.AspNet.CS.Controls