如何在SqlDataSource中传递动态值?

时间:2013-09-06 09:17:47

标签: c# asp.net

我需要在Request.QueryString

中传递此值asp:SqlDataSource
 <asp:SqlDataSource runat="server" 
                    ID="SqlDataSource2" ConnectionString='<%$ ConnectionStrings:messageexchangeConnectionString %>' 
                    ProviderName='<%$ ConnectionStrings:messageexchangeConnectionString.ProviderName %>' 
                    SelectCommand='SELECT distribution_address FROM exchange_distribution_groups ex WHERE (organisation_id = 'Request.QueryString["organisation"]') AND (distribution_address NOT IN (SELECT distribution_address FROM exchange_distribution_group_addresses address))'>     
 </asp:SqlDataSource>

2 个答案:

答案 0 :(得分:2)

您可以使用此

     <asp:SqlDataSource runat="server" ID="SqlDataSource2"
         ConnectionString='<%$ ConnectionStrings:messageexchangeConnectionString %>'
         ProviderName='<%$ ConnectionStrings:messageexchangeConnectionString.ProviderName %>'
         SelectCommand='SELECT distribution_address FROM exchange_distribution_groups ex WHERE (organisation_id = '<%# Request.QueryString["organisation"] %> ') AND (distribution_address NOT IN (SELECT distribution_address FROM exchange_distribution_group_addresses address))'>    
     </asp:SqlDataSource>

答案 1 :(得分:2)

试试这个:

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="<%$ ConnectionStrings:messageexchangeConnectionString %>" 
    SelectCommand="SELECT organisation_id,distribution_address FROM exchange_distribution_groups ex WHERE (([organisation_id] = @id) AND (distribution_address NOT IN (SELECT distribution_address FROM exchange_distribution_group_addresses address))">
    <SelectParameters>
        <asp:QueryStringParameter Name="id" QueryStringField="organisation" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>