Dim drop As MyDropDown
drop = CType(e.Item.FindControl("drop1"), MyDropDown)
ds.Tables(0).Rows(row_num)(3) = drop.DropSelectText其中MyDropDown是UserControl的类名。
try it.

解决方案 »

  1.   

    编译器错误信息: BC30002: 未定义类型“MyDropDown”。
      

  2.   

    你的UserControl类名不是MyDropDown,这样看看:
    Response.Write(e.Item.FindControl("drop1").ToString())
    看看输出的控件类名是什么,然后把这个名称代替前面的MyDropDown
      

  3.   

    ASP.MyDropDown_ascx替换后提示ASP.MyDropDown_ascx未定义
      

  4.   

    那你把MyDropDown.ascx写成CodeBehind的形式呢。
      

  5.   

    我不想把所有内容都写在一个文件里,主要是想作出一个通用的控件。。
    现在,我打算用自定义控件来做:
    ========================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?
      

  6.   

    单独建立一个Web Control Library工程,然后把上面类里面的代码拷贝过去。编译之后就是一个独立的.dll文件。
      

  7.   

    ============================================================
    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。