Load Webcontrol Dynamisk
Jeg har en side hvor jeg fylder en dropdown dynamisk:Function FillDDLPage()
MyCommand = New OleDbCommand
MyDS = New DataSet
MyDA = New OleDbDataAdapter
MySQL = "Select * from ProgramDDL_Tbl Where ProgramID=70;"
MyCommand.CommandText = MySQL
MyCommand.Connection = MyConnection
MyDA.SelectCommand = MyCommand
Try
MyDA.Fill(MyDS)
Catch ex As Exception
Lblmessage.Text = ex.ToString
Lblmessage.Visible = True
'Exit Sub
End Try
Try
DDLPage.DataSource = MyDS
DDLPage.DataValueField = "DDLValue"
DDLPage.DataTextField = "DDLText"
DDLPage.DataBind()
Catch ex As Exception
Lblmessage.Text = ex.ToString
Lblmessage.Visible = True
'Exit Sub
End Try
DDLPage.Items.Insert(0, "...Select...")
End Function
Ud fra den valgte linie i denne dropdown vil jeg gerne loade en webcontrol.
Eksempel:
Bruger brugeren vælger ”User Groups” i min dropdown.
DDLPage.SelectedValue = User_Groups
Derefter skal der nogen lunde sket dette:
Private Sub DDLPage_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDLPage.SelectedIndexChanged
Display “DDLPage.SelectedValue”.ascx
End Sub
Ergo skal den loade den webcontrol der hedder User_Groups.ascx ind på min side Page_AdminUsers.aspx v.h.a. min dropdown.
Indtil nu har jeg gjort det således:
<asp:DropDownList ID="DDLPage" runat="server" AutoPostBack="true">
<asp:ListItem Value="0">..Select Type..</asp:ListItem>
<asp:ListItem Value="Groups">User Groups</asp:ListItem>
<asp:ListItem Value="Access">User Access</asp:ListItem>
</asp:DropDownList>
Private Sub DDLDisplay_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDLDisplay.SelectedIndexChanged
Select Case DDLDisplay.SelectedValue
Case 0
User_Access1.Visible = False
User_Groups1.Visible = False
Case "Groups"
User_Access1.Visible = False
User_Groups1.Visible = True
Case "Access"
User_Access1.Visible = True
User_Groups1.Visible = False
End Select
End Sub