从代码隐藏中添加SqlDataSource中的参数

时间:2013-02-19 12:30:55

标签: c# asp.net

我的页面上有一个网格,我想填充存储过程提供的数据,它有一些从cookie读取的参数。我不知道如何动态地将参数添加到SqlDataSource并将其分配给网格?

 </telerik:RadScriptManager>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Height="200px" 
    Width="715px">
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" 
        AllowSorting="True" CellSpacing="0"  GridLines="None" 
        Height="533px" PageSize="7" AllowFilteringByColumn="True" 
        FilterItemStyle-Width="400px" DataSourceID="dsNew">
        <ClientSettings>
            <Selecting CellSelectionMode="None" />
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
        </ClientSettings>
        <AlternatingItemStyle BackColor="#CCCCCC" />
        <MasterTableView datasourceid="dsNew">
            <CommandItemSettings ExportToPdfText="Export to PDF" />
            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" 
                Visible="True">
            </RowIndicatorColumn>
            <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" 
                Visible="True">
            </ExpandCollapseColumn>
            <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                </EditColumn>
            </EditFormSettings>
        </MasterTableView>
        <FilterItemStyle Width="400px" />
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
    </telerik:RadGrid>
    <asp:SqlDataSource ID="dsNew" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_BankSafeDepositBoxesConnectionString %>" 
        SelectCommand="S_Boxes_StatusReport" SelectCommandType="StoredProcedure">
       <SelectParameters>
             <asp:CookieParameter Name="BranchID" CookieName="userauth" />
            </SelectParameters>
    </asp:SqlDataSource>

1 个答案:

答案 0 :(得分:0)

您可以按如下方式使用: -

    <SelectParameters>
        <asp:CookieParameter Name="email" CookieName="email_id" />
    </SelectParameters>

MSDN链接
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.cookieparameter.aspx