Link to home
Start Free TrialLog in
Avatar of DLockwood
DLockwood

asked on

Bind string value to AccessDataSource Parameter

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     Dim sUserID As String = User.Identity.Name
     PermittedAccessList_DS.SelectParameters(0).DefaultValue = sUserID
End Sub

Why doesn't Drop Down List show values based on the Parameter?
Avatar of MogalManic
MogalManic
Flag of United States of America image

Try calling Databind() on the Dropdown control after setting the parameter.
Avatar of DLockwood
DLockwood

ASKER

Doesn't fix anything.

Still doesn't work.
Can you post some more snippets of the code?  Specifically the accessdatasource and the droplist.
Sure, gimme a second.

Funny thing is that I read I should put my Code Behind into the DDL_Selecting Event. I do not even get that option.
DDL:
        <asp:DropDownList ID="DDLTables" runat="server"
            AutoPostBack="True"
            DataSourceID="PermittedAccessList_DS"
            DataTextField="TableSecurity"
            DataValueField="TableSecurity"
            AppendDataBoundItems="True"
            style="text-align:
            center" Width="250px">
            <asp:ListItem Text="Select a Program to Access" Value="" />
        </asp:DropDownList>

DataSource:
<asp:AccessDataSource ID="PermittedAccessList_DS" runat="server"
        DataFile="~/App_Data/OutcomesDB.mdb"
        SelectCommand="SELECT tlkp_TableSecurity.TableSecurity FROM (tlkp_TableSecurity INNER JOIN tlkp_UserSecurity ON tlkp_TableSecurity.ID = tlkp_UserSecurity.TABLE) WHERE (Username = ?) ORDER BY tlkp_TableSecurity.TableSecurity">
        <SelectParameters>
            <asp:Parameter Name="UserName" Type="string"  />
        </SelectParameters>
    </asp:AccessDataSource>

Code Behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sUserID As String = "David"
        PermittedAccessList_DS.SelectParameters(0).DefaultValue = sUserID
        DDLTables.DataBind()
End Sub

DOESN'T WORK
OK - So the DDL doesn't have the SELECTING event, it is the data source. Duh!

But, even when I put the code like this, it doesn't work.....

    Private Sub PermittedAccessList_DS_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles PermittedAccessList_DS.Selecting
        Dim sUserID As String = "David"
        PermittedAccessList_DS.SelectParameters(0).DefaultValue = sUserID
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of DLockwood
DLockwood

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Answered it myself.