当此下拉列表来自UserControl时,如何从dropdownlist获取值以进行绑定?

时间:2013-04-18 11:57:23

标签: .net vb.net drop-down-menu user-controls bind

我的UserControl(UCProducs)中有3个下拉列表(cbb_state,cbb_products,cbb_item),每个都有一个DataSource(ods_state,ods_products,ods_item),我有我的.aspx页面,即使用此UserControl。 ..并且这个页面有和ObjectDataSource一样,必须绑定我的UserControl中我的3个下拉列表中的值...我已经尝试了一些例子,但没有一个帮助我。

这是我的UserControl代码文件:

Imports System.Data.SqlClient
Partial Class UCProducts
Inherits System.Web.UI.UserControl

Public Property Item() As Integer
    Get
        If cbb_item.SelectedValue <> "" Then
            Return cbb_item.SelectedValue
        Else
            Return 0
        End If
    End Get
    Set(ByVal value As Integer)
        cbb_item.SelectedValue = value
        Distrito = fc_produts.value)
        If value > 0 Then
            cbb_products.Enabled = True

        End If
    End Set
End Property

Public Property State() As Integer
    Get
        If cbb_state.SelectedValue <> "" Then
            Return cbb_state.SelectedValue
        Else
            Return 0
        End If
    End Get
    Set(ByVal value As Integer)
        If Not value = 0 Then
            cbb_state.SelectedValue = value

        End If

    End Set
End Property

Public Property Products() As Integer
    Get
        Return cbb_products.SelectedValue
    End Get
    Set(ByVal value As Integer)
        cbb_products.SelectedValue = value
    End Set
End Property




Private Function fc_pega_sub(ByVal index As Integer) As Integer

        'my code
End Function

Private Function fc_pega_distrito(ByVal value As Integer) As Integer

        'my code
End Function



Protected Sub cbb_regiao_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbb_regiao.SelectedIndexChanged
    'my code
End Sub
End Class

在我的.aspx页面中:

 <uc5:UCProduts ID="ucProd" runat="server" />

我该怎么做?

1 个答案:

答案 0 :(得分:0)

我终于做到了哈哈 答案很简单...... 因为当我将UserControl放入我的页面时,我创建了我的属性“Products()”,所以我只需要引用属性绑定我的列! 这是解决方案:

<uc2:Products ID="Products" runat="server" Products='<%# Bind("fk_products") %>' />