Session Variable in SQLDataSource

4 posts, 1 answers
  1. Peter Sitero
    Peter Sitero avatar
    15 posts
    Member since:
    Oct 2009

    Posted 08 Dec 2009 Link to this post

    Is it possible to insert a session variable in an SQLDataSource like so:

    ="SELECT * FROM Companies WHERE CompanyID = <%session(CurrentCompID)%>"

  2. Answer
    illumination
    illumination avatar
    85 posts
    Member since:
    May 2008

    Posted 08 Dec 2009 Link to this post

    I believe you can, by creating the SqlDataSource this way:
    <asp:SqlDataSource....
    SelectCommand="Select * from companies where companyid = @CurrentCompID" >
    <SelectParameters>
        <asp:SessionParameter Name="CurrentCompID" SessionField="CurrentCompID" />
    </SelectParameters>
    </asp:SqlDataSource>

    good luck :)
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Peter Sitero
    Peter Sitero avatar
    15 posts
    Member since:
    Oct 2009

    Posted 08 Dec 2009 Link to this post

    Cool, that worked perfectly :-)
  5. Sriramana
    Sriramana avatar
    1 posts
    Member since:
    Dec 2011

    Posted 11 Dec 2011 Link to this post

    Hi, I implemented the following code, bt it is giving error as object reference not found.
    My task is; when i click on edit in grid, it is displaying the form to edit. Now, depending the value in textbox, i have to fill the combobox.

    here i am providing the code. pl help me.
    ========
    <%@ Page Title="" Language="VB" MasterPageFile="~/MasterData.master" AutoEventWireup="false"
        CodeFile="MasterCustomer.aspx.vb" Inherits="MasterCustomer" %>


    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <%@ Register TagPrefix="sds" Namespace="Telerik.Web.SessionDS" %>


    <asp:Content ID="Content1" ContentPlaceHolderID="phMain" runat="Server">
        <telerik:RadGrid ID="rgMasterCustomer" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            CellSpacing="0" DataSourceID="sdsMasterCustomer" Skin="WebBlue"  AllowAutomaticUpdates="True"
            GridLines="None" PageSize="25" AllowSorting="True" AutoGenerateEditColumn="true">
            <MasterTableView DataSourceID="sdsMasterCustomer" DataKeyNames="CUSTOMER_UID" AllowFilteringByColumn="True">
                <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                    <HeaderStyle Width="20px"></HeaderStyle>
                </RowIndicatorColumn>
                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                    <HeaderStyle Width="20px"></HeaderStyle>
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridBoundColumn DataField="CUSTOMER_UID" FilterControlAltText="Filter UID column"
                        HeaderText="UID" UniqueName="CUSTOMER_UID" AllowSorting="False">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="CUSTOMER" FilterControlAltText="Filter Customer column"
                        HeaderText="Customer" UniqueName="Customer" AllowSorting="False">
                    </telerik:GridBoundColumn>
                    


                    <telerik:GridDropDownColumn DataField="CUSTOMER_COMMON_NAME" DataSourceID="SqlDataSource1"
                        HeaderText="Common Name" ListTextField="CUSTOMER_COMMON_NAME" ListValueField="CUSTOMER_COMMON_NAME"
                        UniqueName="CommonName" ColumnEditorID="GridDropDownColumnEditor1" DropDownControlType="RadComboBox">
                    </telerik:GridDropDownColumn>


                    <telerik:GridBoundColumn DataField="PARENT_CUSTOMER" FilterControlAltText="Filter Parent column"
                        HeaderText="Parent" ShowSortIcon="true" UniqueName="Parent">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="TOP_PARENT_CUSTOMER" FilterControlAltText="Filter TopParent column"
                        HeaderText="Top Parent" ShowSortIcon="true" UniqueName="TopParent">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="END_CUSTOMER" FilterControlAltText="Filter EndCustomer column"
                        HeaderText="End Customer" ShowSortIcon="true" UniqueName="EndCustomer">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="MARKET_SEGMENT" FilterControlAltText="Filter EndMarket column"
                        HeaderText="End Market" ShowSortIcon="true" UniqueName="EndMarket">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="CUSTOMER_SEGMENT" FilterControlAltText="Filter CustomerMarket column"
                        HeaderText="Customer Market" ShowSortIcon="true" UniqueName="CustomerMarket">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="UPDATED_FLAG" FilterControlAltText="Filter UpdatedFlag column"
                        HeaderText="Updated Flag " ShowSortIcon="true" UniqueName="UpdatedFlag">
                    </telerik:GridBoundColumn>
                </Columns>
                <EditFormSettings>
                    <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                    </EditColumn>
                </EditFormSettings>
            </MasterTableView>
            <FilterMenu EnableImageSprites="False">
            </FilterMenu>
            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
            </HeaderContextMenu>
        </telerik:RadGrid>
        <telerik:GridDropDownListColumnEditor ID="GridDropDownColumnEditor1" runat="server"
            DropDownStyle-Width="300px" />
        <asp:SqlDataSource ID="sdsMasterCustomer" runat="server" ProviderName="System.Data.SqlClient" ConnectionString="<%$ ConnectionStrings:DataConnectionString %>"
            SelectCommand="SELECT * FROM D_Customer order by UPDATED_FLAG" 
            UpdateCommand="UPDATE [D_Customer] SET [CUSTOMER] = @CUSTOMER, 
            [CUSTOMER_COMMON_NAME] = @CUSTOMER_COMMON_NAME,
            [PARENT_CUSTOMER] = @PARENT_CUSTOMER,
            [TOP_PARENT_CUSTOMER] = @TOP_PARENT_CUSTOMER,
            [END_CUSTOMER] = @END_CUSTOMER,
            [MARKET_SEGMENT] = @MARKET_SEGMENT,
            [CUSTOMER_SEGMENT] = @CUSTOMER_SEGMENT,
            [UPDATED_FLAG] = @UPDATED_FLAG
              WHERE [CUSTOMER_UID] = @original_CUSTOMER_UID" 
             OldValuesParameterFormatString="original_{0}"  ConflictDetection="CompareAllValues">
             
            <UpdateParameters>
                <asp:Parameter Name="CUSTOMER" Type="String" />
                <asp:Parameter Name="CUSTOMER_COMMON_NAME" Type="String" />
                <asp:Parameter Name="PARENT_CUSTOMER" Type="String" />
                <asp:Parameter Name="TOP_PARENT_CUSTOMER" Type="String" />
                <asp:Parameter Name="END_CUSTOMER" Type="String" />
                <asp:Parameter Name="MARKET_SEGMENT" Type="String" />
                <asp:Parameter Name="CUSTOMER_SEGMENT" Type="String" />
                <asp:Parameter Name="UPDATED_FLAG" Type="String" />
                
                <asp:Parameter Name="original_CUSTOMER_UID" Type="String" />
                <asp:Parameter Name="original_END_CUSTOMER" Type="String" />
            </UpdateParameters>
            </asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString %>"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT [CUSTOMER_COMMON_NAME], [CUSTOMER] FROM [D_Customer] WHERE [CUSTOMER] = @CUSTOMER" >
            <SelectParameters>
        <asp:SessionParameter Name="CUSTOMER" SessionField="CUSTOMER" Type="string" />
      </SelectParameters>
           
        </asp:SqlDataSource>


    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="phMenu" runat="Server">
    </asp:Content>

Back to Top