TXT

webtable

By Vincent Rose,2014-05-27 15:12
7 views 0
webtable

     ??ÎÄÓÉlnsoftwwl??Ï×

     using System;

     using System.Runtime.InteropServices;

     using System.Web.UI;

     using System.Web.UI.WebControls.WebParts;

     using System.Xml.Serialization;

     using System.Collections;

     using Microsoft.SharePoint;

     using Microsoft.SharePoint.WebControls;

     using Microsoft.SharePoint.WebPartPages;

     using System.ComponentModel;

     namespace MyPart

     {

     [Guid("9eb18c96-ce55-4a8b-8e08-e6db886c0320")]

     public class MyPart : Microsoft.SharePoint.WebPartPages.WebPart,

    IWebPartParameters

     {

     public MyPart()

     {

     this.ExportMode = WebPartExportMode.All;

     }

     protected override void Render(HtmlTextWriter writer)

     {

     writer.Write( "hello,world!" );

     }

     #region other connecton interfaces

     //[ConnectionConsumer("IWebPartField", "IWebPartField")]

     //public void SetObj( IWebPartField f )

     //{

     //}

     //[ConnectionConsumer("IWebPartRow", "IWebPartRow")]

     //public void SetObj(IWebPartRow f)

     //{

     //}

     //[ConnectionConsumer("IWebPartTable", "IWebPartTable")]

     //public void SetObj(IWebPartTable f)

     //{

     //}

     #endregion

     [ConnectionProvider("IWebPartParameters", "IWebPartParameters")]

     public IWebPartParameters ProviderIWebPartParameters()

     {

     return this;

     }

     #region IWebPartParameters ?ÉÔ?

     public void GetParametersData(ParametersCallback callback)

     {

     //?Ë????ÕÕ_schemaµÄ×Ö?ÎÃû?µ?Ø?ýÂËÒÀ?Ý

     IDictionary dic = new Hashtable();

     //dic.Add("KeyWord" , this.KeyWord );

     dic.Add("LinkTitle", "XXX"); //??ÕÕ?êÌâ?ýÂË

     callback(dic);

     }

     public System.ComponentModel.PropertyDescriptorCollection Schema

     {

     get

     {

     return _schema;??????????????

     //PropertyDescriptorCollection properties =

     //????TypeDescriptor.GetProperties(this, new Attribute[] { new

    WebBrowsableAttribute() });

     //return properties;

     }

     }

     private PropertyDescriptorCollection _schema;

     public void

    SetConsumerSchema(System.ComponentModel.PropertyDescriptorCollecti

    on schema)

     {

     _schema = schema;

     }

     #endregion

     }

     }

     Imports System

     Imports System.Collections

     Imports System.ComponentModel

     Imports System.Data

     Imports System.Reflection

     Imports System.Security.Permissions

     Imports System.Web

     Imports System.Web.UI

     Imports System.Web.UI.WebControls

     Imports System.Web.UI.WebControls.WebParts

     Namespace Samples.aspNet.vb.Controls

     ' This sample code creates a Web Parts control that acts as a provider

     ' of table data.

     _

     _

     Public NotInheritable Class TableProviderWebPart

     Inherits WebPart

     Implements IWebPartTable

     Private _table As DataTable

     Public Sub New()

     _table = New DataTable()

     Dim col As New DataColumn()

     col.DataType = GetType(String)

     col.ColumnName = "Name"

     _table.Columns.Add(col)

     col = New DataColumn()

     col.DataType = GetType(String)

     col.ColumnName = "Address"

     _table.Columns.Add(col)

     col = New DataColumn()

     col.DataType = GetType(Integer)

     col.ColumnName = "ZIP Code"

     _table.Columns.Add(col)

     Dim row As DataRow = _table.NewRow()

     row("Name") = "John Q. Public"

     row("Address") = "123 Main Street"

     row("ZIP Code") = 98000

     _table.Rows.Add(row)

     End Sub

     Public ReadOnly Property Schema() As _

     ComponentModel.PropertyDescriptorCollection Implements

    IWebPartTable.Schema

     Get

     Return TypeDescriptor.GetProperties(_table.DefaultView(0))

     End Get

     End Property

     Public Sub GetTableData(ByVal callback As TableCallback) _

     Implements IWebPartTable.GetTableData

     callback(_table.Rows)

     End Sub

     Public Property ConnectionPointEnabled() As Boolean

     Get

     Dim o As Object = ViewState("ConnectionPointEnabled")

     Return IIf(Not (o Is Nothing), CBool(o), True)

     End Get

     Set(ByVal value As Boolean)

     ViewState("ConnectionPointEnabled") = value

     End Set

     End Property

     _

     Public Function GetConnectionInterface() As IWebPartTable

     Return New TableProviderWebPart()

     End Function

     End Class 'TableProviderWebPart

     ' The connection point for the provider control.

     _

     _

     Public Class TableProviderConnectionPoint

     Inherits ProviderConnectionPoint

     Public Sub New(ByVal callbackMethod As MethodInfo, _

     ByVal interfaceType As Type, ByVal controlType As Type, _

     ByVal name As String, ByVal id As String, _

     ByVal allowsMultipleConnections As Boolean)

     MyBase.New(callbackMethod, interfaceType, controlType, _

     name, id, allowsMultipleConnections)

     End Sub

     Public Overrides Function GetEnabled(ByVal control _

     As Control) As Boolean

     Return CType(control,

    TableProviderWebPart).ConnectionPointEnabled

     End Function

     End Class

     ' This code sample creates a Web Parts control that acts as a consumer

     ' of information provided by the TableProvider.ascx control.

     _

     _

     Public Class TableConsumer

     Inherits WebPart

     Private _provider As IWebPartTable

     Private _tableData As ICollection

     Private Sub GetTableData(ByVal tableData As ICollection)

     _tableData = CType(tableData, ICollection)

     End Sub

     Protected Overrides Sub OnPreRender(ByVal e As EventArgs)

     If Not (_provider Is Nothing) Then

     _provider.GetTableData(New TableCallback(AddressOf GetTableData))

     End If

     End Sub

     Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)

     If Not (_provider Is Nothing) Then

     Dim props As PropertyDescriptorCollection = _provider.Schema

     Dim count As Integer = 0

     If Not (props Is Nothing) AndAlso props.Count > 0 _

     AndAlso Not (_tableData Is Nothing) Then

     Dim prop As PropertyDescriptor

     For Each prop In props

     Dim o As DataRow

     For Each o In _tableData

     writer.Write(prop.DisplayName & ": " & o(count))

     Next o

     writer.WriteBreak()

     writer.WriteLine()

     count = count + 1

     Next prop

     Else

     writer.Write("No data")

     End If

     Else

     writer.Write("Not connected")

     End If

     End Sub

     _

     Public Sub SetConnectionInterface(ByVal provider As IWebPartTable)

     _provider = provider

     End Sub

     End Class 'TableConsumer

     ' The connection point for the consumer control.

     _

     _

     Public Class TableConsumerConnectionPoint

     Inherits ConsumerConnectionPoint

     Public Sub New(ByVal callbackMethod As MethodInfo, _

     ByVal interfaceType As Type, ByVal controlType As Type, _

     ByVal name As String, ByVal id As String, _

     ByVal allowsMultipleConnections As Boolean)

     MyBase.New(callbackMethod, interfaceType, controlType, name, _

     id, allowsMultipleConnections)

     End Sub

     End Class 'TableConsumerConnectionPoint

     End Namespace ' Samples.AspNet.CS.Controls

     created a web part for sharepoint to Provided a Datasource for a

    chart ,with IWebPartTable,

     and now the question is ,I want add a event for this Class, so when

a click a button ,then the DataSourse should be changed. what should

    I do ,

     the code ,which I write in the following:

     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 table data.

     [AspNetHostingPermission(SecurityAction.Demand,

     Level = AspNetHostingPermissionLevel.Minimal)]

     [AspNetHostingPermission(SecurityAction.InheritanceDemand,

     Level = AspNetHostingPermissionLevel.Minimal)]

     public sealed class TableProviderWebPart : WebPart, IWebPartTable

     {

     private TableCell _HtmlTableCell = new TableCell();

     DataTable _table=new DataTable();

     private TextBox _TxtDate1 = new TextBox();

     private TextBox _TxtDate2 = new TextBox();

     private RadioButton _RbtnCont1 = new RadioButton();

     private RadioButton _RbtnCont2= new RadioButton();

     private Button _ButtonSerch = new Button();

     public TableProviderWebPart()

     {

     _RbtnCont1.GroupName = "conttype";

     _RbtnCont2.GroupName = "conttype";

     _RbtnCont1.Checked = true;

     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);

     this.GetItems();

     }

     protected override void CreateChildControls()

     {

     this.Controls.Add(new LiteralControl("

     "));

     this.Controls.Add(new LiteralControl("????

     "));

     this.Controls.Add(this._HtmlTableCell);

     this.Controls.Add(new LiteralControl("????"));

     this.Controls.Add(new LiteralControl(""));

     if (this.Page.IsPostBack == false) this.AddRows();

     }

     protected override void OnLoad(EventArgs e)

     {

     base.OnLoad(e);

     if (this.Page.IsPostBack == true) this.AddRows();

     }

     private void GetItems()

     {

     this._ButtonSerch.Click += delegate(object sender, EventArgs e)

     {

     if (_TxtDate1.Text == "1")

     {

     DataRow row = _table.NewRow();

     row["Name"] = "John Q. Public";

     row["Address"] = "123 Main Street";

     row["ZIP Code"] = 98000;

     _table.Rows.Add(row);

     row = _table.NewRow();

     row["Name"] = "sss Q. Public";

     row["Address"] = "444 Main Street";

     row["ZIP Code"] = 45000;

     _table.Rows.Add(row);

     }

     else

     {

     DataRow row = _table.NewRow();

     row["Name"] = "John Q. Public";

     row["Address"] = "123 Main Street";

     row["ZIP Code"] = 33000;

     _table.Rows.Add(row);

     row = _table.NewRow();

     row["Name"] = "sss Q. Public";

     row["Address"] = "444 Main Street";

     row["ZIP Code"] = 22000;

     _table.Rows.Add(row);

     }

     };

     }

     private void AddRows()

     {

     this._HtmlTableCell.Controls.Add(new LiteralControl("

     "));

     this._HtmlTableCell.Controls.Add(new LiteralControl("

     "));

     this._HtmlTableCell.Controls.Add(new LiteralControl("Date1:"));

     this._TxtDate1.ID = "_TxtDate1";

     this._TxtDate1.Text = "";

     this._HtmlTableCell.Controls.Add(this._TxtDate1);

     this._HtmlTableCell.Controls.Add(new LiteralControl("

     "));

     this._HtmlTableCell.Controls.Add(new LiteralControl("Date2:"));

     this._TxtDate2.ID = "_TxtDate2";

     this._TxtDate2.Text = "";

     this._HtmlTableCell.Controls.Add(this._TxtDate2);

     this._HtmlTableCell.Controls.Add(new LiteralControl("

     "));

     this._HtmlTableCell.Controls.Add(new LiteralControl("From:"));

     this._RbtnCont1.ID = "_RbtnCont1";

     this._RbtnCont1.Text = "One List Blockers Only";

     this._HtmlTableCell.Controls.Add(this._RbtnCont1);

     this._RbtnCont2.ID = "_RbtnCont2";

     this._RbtnCont2.Text = "Blockers form All Listening Systems";

     this._HtmlTableCell.Controls.Add(this._RbtnCont2);

     this._HtmlTableCell.Controls.Add(new LiteralControl("

     "));

     this._HtmlTableCell.Controls.Add(new LiteralControl(""));

     this._ButtonSerch.ID = "_ButtonSerch";

     this._ButtonSerch.Text = "";

     this._HtmlTableCell.Controls.Add(this._ButtonSerch);

     this._HtmlTableCell.Controls.Add(new LiteralControl(""));

     this._HtmlTableCell.Controls.Add(new LiteralControl(""));

     }

     protected override void Render(HtmlTextWriter writer)

     {

     base.Render(writer);

     }

     public PropertyDescriptorCollection Schema

     {

     get

     {

     return TypeDescriptor.GetProperties(_table.DefaultView[0]);

     }

     }

     public void GetTableData(TableCallback callback)

     {

     callback(_table.Rows);

     }

     public bool ConnectionPointEnabled

     {

     get

     {

     object o = ViewState["ConnectionPointEnabled"];

     return (o != null) ? (bool)o : true;

     }

     set

     {

     ViewState["ConnectionPointEnabled"] = value;

     }

     }

     [ConnectionProvider("Table",

    typeof(TableProviderConnectionPoint),

     AllowsMultipleConnections = true)]

     public IWebPartTable GetConnectionInterface()

     {

     return new TableProviderWebPart();

     }

     public class TableProviderConnectionPoint : ProviderConnectionPoint

     {

     public TableProviderConnectionPoint(MethodInfo callbackMethod,

     Type interfaceType, Type controlType, string name, string id,

     bool allowsMultipleConnections)

     : base(callbackMethod, interfaceType, controlType, name, id,

     allowsMultipleConnections)

     {

     }

     public override bool GetEnabled(Control control)

     {

     return ((TableProviderWebPart)control).ConnectionPointEnabled;

     }

     }

     }

     // This code sample creates a Web Parts control that acts as a consumer

     // of information provided by the TableProvider.ascx control.

     [AspNetHostingPermission(SecurityAction.Demand,

     Level = AspNetHostingPermissionLevel.Minimal)]

     [AspNetHostingPermission(SecurityAction.InheritanceDemand,

     Level = AspNetHostingPermissionLevel.Minimal)]

     public class TableConsumer : WebPart

     {

     private IWebPartTable _provider;

     private ICollection _tableData;

     private void GetTableData(object tableData)

     {

     _tableData = (ICollection)tableData;

     }

     protected override void OnPreRender(EventArgs e)

     {

     if (_provider != null)

     {

     _provider.GetTableData(new TableCallback(GetTableData));

     }

     }

     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();

Report this document

For any questions or suggestions please email
cust-service@docsford.com