你先建一个WebControlLibrary,删除自带的WebCustomControl 在下面建你命名的WebCustomControl 比如你建的控件是继承DropDownListImports System.ComponentModel Imports System.Web.UI Imports System.Web.UI.Control Imports System.Web.UI.WebControls<DefaultProperty("Text"), ToolboxData _ ("<{0}:myDropDownList runat=server></{0}:myDropDownList>")> _ Public Class myDropDownList Inherits DropDownList Private mTypeCode As String
#Region "属性"
<Category("data"), Description("my"), DefaultValue("")> _ Public Property TypeCode() As String Get Return mTypeCode End Get Set(ByVal Value As String) mTypeCode = Value End Set End Property #End Region Protected Overrides Sub CreateChildControls() MyBase.CreateChildControls() End Sub Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter) MyBase.Render(writer) End Sub Public Function FillDropDownList() As Boolean .......your code End Function End ClassTypeCode就是你添加的属性,FillDropDownList就是你添加的方法. 编译后会生成相应的.dll,在你的工程里引用,然后加到你的工具箱里,要用的时候拖到页面上. 自定义控件的内容很多,也很复杂,我也搞不太清. 要么找点专门的教材看看,要么干脆down dll
//MyDataGrid.cs using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace webUserWindowExample { /// <summary> /// Summary description for MyDataGrid. /// </summary> public class MyDataGrid:System.Web.UI.WebControls.DataGrid { private string url; public string Url { get { return this.url ; } set { this.url =value; } } public MyDataGrid() { // // TODO: Add constructor logic here // } protected override void OnItemCreated(DataGridItemEventArgs e) {
在下面建你命名的WebCustomControl
比如你建的控件是继承DropDownListImports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.Control
Imports System.Web.UI.WebControls<DefaultProperty("Text"), ToolboxData _
("<{0}:myDropDownList runat=server></{0}:myDropDownList>")> _
Public Class myDropDownList
Inherits DropDownList Private mTypeCode As String
#Region "属性"
<Category("data"), Description("my"), DefaultValue("")> _
Public Property TypeCode() As String
Get
Return mTypeCode
End Get
Set(ByVal Value As String)
mTypeCode = Value
End Set
End Property
#End Region Protected Overrides Sub CreateChildControls()
MyBase.CreateChildControls()
End Sub Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
MyBase.Render(writer)
End Sub Public Function FillDropDownList() As Boolean
.......your code
End Function
End ClassTypeCode就是你添加的属性,FillDropDownList就是你添加的方法.
编译后会生成相应的.dll,在你的工程里引用,然后加到你的工具箱里,要用的时候拖到页面上.
自定义控件的内容很多,也很复杂,我也搞不太清.
要么找点专门的教材看看,要么干脆down dll
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace webUserWindowExample
{
/// <summary>
/// Summary description for MyDataGrid.
/// </summary>
public class MyDataGrid:System.Web.UI.WebControls.DataGrid
{
private string url;
public string Url
{
get
{
return this.url ;
}
set
{
this.url =value; }
}
public MyDataGrid()
{
//
// TODO: Add constructor logic here
//
}
protected override void OnItemCreated(DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onclick","window.open('"+this.url+"')");
}
base.OnItemCreated (e);
}
}
}然后在其它的页面上MyDataGrid m=new MyDataGrid();
m.Url ="http://www.csdn.net";
m.DataSource =new string[]{"aaa","bbb"};
m.DataBind();
this.Controls[1].Controls .Add(m);
<cc1:MyDataGrid id="MyDataGrid1" style="Z-INDEX: 102; LEFT: 120px; POSITION: absolute; TOP: 16px"
runat="server">
<Columns>
<asp:TemplateColumn HeaderText="aaaaaa">
<ItemTemplate>
sssss
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</cc1:MyDataGrid>