Search code examples
asp.netsharepointsharepoint-2007

How to pass server variables as SqlDataSource parameter for sharepoint dataformwebpart?


I'm trying to execute a stored procedure via Sharepoint's DataFormWebPart by passing it the currently logged in sharepoint username (a server variable essentially), however, I'm getting stuck on how to pass server variables.

Here is what I have as code

<asp:SqlDataSource runat="server" ProviderName="System.Data.SqlClient" ID="SqlDataSource7" SelectCommandType="StoredProcedure" ConnectionString="xxx;" SelectCommand="xxx" __designer:customcommand="true">
    <SelectParameters>
         <!-- Not sure what to do here -->
    </SelectParameters>
</asp:SqlDataSource>

I know I want to do something like

<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>

But it seems I can only use asp parameter tags...


Solution


  • better late than never :)
    I'm working in 2010, but I guess it should work in 2007 too:

    1. bind appropriate server variable to your DVWP:

      <ParameterBindings>
        ...
        <ParameterBinding Name="LOGON_USER" Location="ServerVariable(LOGON_USER)"/>
      </ParameterBindings>
      
    2. now you can push this parameter into data source:

      <SelectParameters>
        ...
        <WebPartPages:DataFormParameter PropertyName="ParameterValues" ParameterKey="LOGON_USER" Name="Context"/>
      </SelectParameters>
      

    Now you have current IIS user (i.e. DOMAIN\USER) in the SqlDataSource parameter @Context :)