How to Modify SQLDataSource Form Parameters on the fly

I have a datagridview attached to a SQL stored procedure that accepts 2 arguments. One is the employee number and the second is the level of access a user has. I have 2 hidden text box controls on the page that will drive the stored procedure. One is call txtEmployeeNumber and the other is txtAccessLevel. I use 2 functions to pull the currently logged on user's employee number and searches that employee number to figure out if they are an Admin, SuperUser, or just a normal User(Default Option).

Current ASP Markup:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:TextBox ID="txtEmployeeNumber" runat="server"></asp:TextBox>
    <asp:TextBox ID="txtAccessLevel" runat="server"></asp:TextBox>
    <br />
        txtAccessLevel.Text = CamIMS.pt_Functions.AccessLevel(CamIMS.pt_Functions.GetEmployeeNumber())
        txtEmployeeNumber.Text = CamIMS.pt_Functions.GetEmployeeNumber()

Open in new window

I then reference those controls in the SQLDataSOurce:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:IMSConnectionString %>" SelectCommand="EmployeeBalances" SelectCommandType="StoredProcedure">
            <asp:ControlParameter ControlID="txtAccessLevel" Name="type" PropertyName="Text" Type="String" />
            <asp:ControlParameter ControlID="txtEmployeeNumber" Name="EmployeeNumber" PropertyName="Text" Type="Int32" />

Open in new window

The problem I have is that the text boxes remain blank. I have tried setting this in the Page_load area with no luck either. I know this is probably not the best way to do this, so I am open to any suggestions.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Not a very secure approach in my opinion.

Problem is that by the time you have set the textboxes, the SQLDataSource has already retrieved data.

I would suggest that when user logs in, you retrieve the employee ID and access level and store it in the session. Then on this page, use SessionParameter instead of ControlParameter. Example on below link

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.