兩個usercontrol互相傳值
在A裡面透過建立一個事件,將 ChangePageSizeBySelect 讓 default.aspx能夠抓到事件,
讓default.aspx能夠抓到值,然後將值丟給B,做dropdownlist的databind
A.ascx.vb(裡面的dropdownlist 一定要做autopost back)
Public Property GetUC() As String
Get
GetUC = DropDownList1.SelectedValue
End Get
Set (value As String)
DropDownList1.SelectedValue = value
End Set
End Property
Public Delegate Sub UserControlEventHandler (ByVal sender As Object , ByVal str As String )
Public Event ChangePageSizeBySelect As UserControlEventHandler
Protected Sub DropDownList1_SelectedIndexChanged( ByVal sender As Object, ByVal e As System.EventArgs ) Handles DropDownList1.SelectedIndexChanged
RaiseEvent ChangePageSizeBySelect(Me , DropDownList1.SelectedValue)
End Sub
Default.aspx.vb
Protected Sub order_mainCus_code_ChangePageSizeBySelect(sender As Object , str As String ) Handles order_mainCus_code.ChangePageSizeBySelect
order_mainDiscus_customer.GetUC() = order_mainCus_code.GetUC()
End Sub
B.ascx.vb
Public Property GetUC() As String
Get
GetUC = DropDownList1.SelectedValue
End Get
Set (value As String)
Dim conn = New SqlConnection
Dim cmd As SqlCommand
Dim adapter As New SqlDataAdapter
Dim ds As New DataSet
Dim dt As New DataTable
Dim SqlString As String
conn.ConnectionString = System.Web.Configuration.WebConfigurationManager .ConnectionStrings( "ConnectionString").ConnectionString() '使用web config
SqlString = "select * from discus_customer where cus_code='" & value & "'"
'Label1.Text = SqlString
adapter = New SqlDataAdapter (SqlString, conn)
adapter.Fill(ds, "Discus_customer" )
DropDownList1.DataValueField = "discus_code"
DropDownList1.DataTextField = "discus_name"
DropDownList1.DataSource = ds.Tables( "Discus_customer" ).DefaultView
DropDownList1.DataBind()
Label1.Text = SqlString
End Set
End Property
0 意見:
張貼留言