This is a migrated thread and some comments may be shown as answers.
Session Variable in SQLDataSource
4 Answers 101 Views
This is a migrated thread and some comments may be shown as answers.
Peter Sitero
Top achievements
Rank 1
Peter Sitero asked on 08 Dec 2009, 05:51 PM

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

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

4 Answers, 1 is accepted

Sort by
0
Accepted
illumination
Top achievements
Rank 2
answered on 08 Dec 2009, 07:31 PM
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 :)
0
Peter Sitero
Top achievements
Rank 1
answered on 08 Dec 2009, 07:52 PM
Cool, that worked perfectly :-)
0
Sriramana
Top achievements
Rank 1
answered on 11 Dec 2011, 08:56 PM
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>

0
Afsah
Top achievements
Rank 1
answered on 03 Jan 2018, 06:41 PM
thats alot.it worked for me too.
Tags
Grid
Asked by
Peter Sitero
Top achievements
Rank 1
Answers by
illumination
Top achievements
Rank 2
Peter Sitero
Top achievements
Rank 1
Sriramana
Top achievements
Rank 1
Afsah
Top achievements
Rank 1
Share this question
or