在定制控件中如何捕获DropDownList控件的SelectedIndexChanged事件?

解决方案 »

  1.   

    How did you create your control?dim ddl as new DropDownList
    ddl.ID = "ddl"
    Controls.Add(ddl)
    AddHandler ddl.SelectedIndexChanged, AddressOf Your_SelectedIndexChanged
    ...
    Private Sub Your_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    '....
    End Sub
      

  2.   

    在DropDownList控件的SelectedIndexChanged中RaiseBubbleEvent()向上层抛出事件然后在定制控件中重写方法OnBubbleEvent(),就可以捕获DropDownList抛出的事件
      

  3.   

    声明
    Protected WithEvents myDropDownList As New System.Web.UI.WebControls.DropDownList
    Protected WithEvents myTable As New System.Web.UI.WebControls.Table
    Dim MyTableRow As TableRow = New TableRow
    Dim MyTableCell As TableCell = New TableCell
    MyTableCell.Controls.Add(myDropDownList)
    MyTableRow.Cells.Add(MyTableCell)
    myTable.Rows.Add(MyTableRow)。

    Protected Overrides Sub CreateChildControls()
    Controls.Add(myTable)
    Controls.Add(myDropDownList)
    End Sub。
    Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
    MyBase.Render(output)
    End Sub
      

  4.   

    myDropDownList.AutoPostBack = True
    但是但选择时不能捕获DropDownList控件的SelectedIndexChanged事件
      

  5.   

    http://chs.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/ctrlauth/composition/Composition3.src&file=VB\Composition3.vb&font=3
      

  6.   

    在VB.net中,只要在控件中定义了Protected WithEvents myDropDownList As DropDownList,然后在代码区域的顶部选择myDropDownList,右边选择SeletedIndexChange事件,编辑焦点就会进入这个事件,然后写你的代码。