Dim drop As MyDropDown
drop = CType(e.Item.FindControl("drop1"), MyDropDown)
ds.Tables(0).Rows(row_num)(3) = drop.DropSelectText其中MyDropDown是UserControl的类名。
try it.
drop = CType(e.Item.FindControl("drop1"), MyDropDown)
ds.Tables(0).Rows(row_num)(3) = drop.DropSelectText其中MyDropDown是UserControl的类名。
try it.
Response.Write(e.Item.FindControl("drop1").ToString())
看看输出的控件类名是什么,然后把这个名称代替前面的MyDropDown
现在,我打算用自定义控件来做:
========================MyDropDownControlsVB.vb。Option Strict Off
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports system.data
Namespace MyDropDownControls
Public Class MyDropDown : Inherits Control
Public Property Value As Integer
Get
Dim Ctrl As dropdownlist = Controls(1)
Me.EnsureChildControls()
Return Ctrl.SelectedItemText
End Get
End Property
Protected Overrides Sub CreateChildControls()
Dim drop As New dropdownlist
Dim xmlds As DataSet=new dataset()
xmlds.ReadXml(Server.MapPath("new_class.xml"))
drop.DataSource=xmlds
drop.DataBind()
Me.Controls.Add(drop)
End Sub
End Class
End Namespace然后调用:
<%@ Register TagPrefix="MyDropDownControls" Namespace="MyDropDownControls" Assembly="MyDropDownControlsVB" %>
<html>
<body>
<form runat=server> <MyDropDownControls:MyDropDown id="MyControl" runat=server/> </form> </body></html>
这样能行吗?如果可以我怎样将MyDropDownControlsVB.vb编译成DLL?
WebCustomControl1.vb:
Option Strict Off
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Namespace MyDropDownControls
Public Class MyDropDown:Inherits Control
Public ReadOnly Property Value() As Integer
Get
Dim Ctrl As DropDownList = Controls(0)
Me.EnsureChildControls()
Return Ctrl.SelectedItem.Text
End Get
End Property
Protected Overrides Sub CreateChildControls()
Dim drop As New DropDownList()
Dim xmlds As DataSet = New DataSet()
xmlds.ReadXml("new_class.xml")
drop.DataSource = xmlds
drop.DataBind()
Me.Controls.Add(drop)
End Sub
End Class
End Namespace编译成WebControlLibrary1.dll
引用:
<%@ Register TagPrefix="MyDropDownControls" Namespace="MyDropDownControls"
Assembly="WebControlLibrary1" %>
<html>
<body>
<form runat=server>
<MyDropDownControls:MyDropDown id="MyControl" runat=server/>
</form>
</body>
</html>
错误:分析器错误信息: 未能从程序集 WebControlLibrary1, Version=1.0.871.24578, Culture=neutral, PublicKeyToken=null 中加载类型 MyDropDownControls.MyDropDown。