简体   繁体   中英

Add parameter in SqlDataSource from code-behind

I have a grid on my page that I want to fill with data that is provided by a stored procedure that it has some parameter that is read from a cookie. I don't know how can I add parameter to SqlDataSource dynamically and assign it to grid?

 </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>

You can use as follows:-

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM