This is a migrated thread and some comments may be shown as answers.

How to get the data from a sessiondatasource?

1 Answer 107 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jorge Saa-Gerbier
Top achievements
Rank 1
Jorge Saa-Gerbier asked on 04 Feb 2011, 12:46 PM

How to get the data from a sessiondatasource?
I get the following scenario:

The code the .aspx is as below:

<sds:SessionDataSource 
        DisplayWarning                  = "False"    
        PrimaryKeyFields                = "dp_key"
        ProviderName                    = "System.Data.SqlClient"
        ID                                         = "devis" 
        runat                                    = "server" 
        ConnectionString                = "<%$ ConnectionStrings:xxxxxxxxxx_Connection %>" 
        ConflictDetection               = "CompareAllValues" 
        OldValuesParameterFormatString  = "original_{0}"
        SelectCommand="SELECT * FROM [devis] ORDER BY dp_key"
        DeleteCommand="DELETE   FROM [devis] WHERE [dp_key] = ?"
        InsertCommand="INSERT   INTO devis(dp_codeprd, dp_nombre, dp_convives, dp_prixs, dp_prixs_unitaire) VALUES (?, ?, ?, ?, ? )" 
           
        >
        <DeleteParameters>
            <asp:Parameter Name="original_dp_key"               Type="Int32"   />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="dp_codeprd"                    Type="String"   />
            <asp:Parameter Name="dp_nombre"                     Type="String"   />
            <asp:Parameter Name="dp_convives"                   Type="Int16"    />
            <asp:Parameter Name="dp_prixs"                      Type="Decimal"  />
            <asp:Parameter Name="dp_prixs_unitaire"             Type="Decimal"  />
        </InsertParameters>
</sds:SessionDataSource>

This definition is used in a RadGrid. The code the .aspx is as below:
<telerik:RadGrid 
        ShowFooter              = "false"
        ID                      = "devis_prd" 
        runat                   = "server"
        DataSourceID            = "devis" 
        Width                   = "100%" 
        AllowPaging             = "True" 
        PageSize                = "10" 
        AllowSorting            = "false"
        GridLines               = "None"
           
        AllowAutomaticDeletes   = "True" 
        AllowAutomaticInserts   = "True"
        AllowAutomaticUpdates   = "True"
        onitemdatabound         = "devis_prd_ItemDataBound" 
    >
    <HeaderContextMenu EnableTheming="True">
        <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
    </HeaderContextMenu>
    <MasterTableView 
        AutoGenerateColumns         = "False" 
        Width                       = "100%"    
        HorizontalAlign             = "NotSet"  
        CommandItemDisplay          = "None" 
        CurrentResetPageIndexAction = "SetPageIndexToFirst"
        DataKeyNames                = "dp_key, dp_prixs" 
        Name                        = "devis_prd"
        NoMasterRecordsText         = "Votre devis est vide !" 
        NoDetailRecordsText         = "Aucun produit sélectionné !"
        >
        <Columns>
            <telerik:GridBoundColumn
                DataField               = "dp_key" 
                HeaderText              = "Id " 
                SortExpression          = "dp_key" 
                UniqueName              = "dp_key"
                DataType                = "System.Int32" 
                ReadOnly                = "True" 
                Visible                 = "False"
                >
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn 
                DataField               = "dp_CodePrd" 
                UniqueName              = "dp_CodePrd"
                HeaderText              = "Code Produit"
                DataType                = "System.String"
                DataFormatString        = "{0:LLL-LL-000}"
                >
                <HeaderStyle HorizontalAlign="Center" /> 
                <ItemStyle   HorizontalAlign="Center" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn 
                DataField               = "dp_nombre" 
                SortExpression          = "dp_nombre" 
                UniqueName              = "dp_nombre"
                HeaderText              = "Nom du Produit"
                DataType                = "System.String" 
                >
                <HeaderStyle HorizontalAlign="Left" /> 
                <ItemStyle   HorizontalAlign="Left" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn 
                DataField               = "dp_convives" 
                SortExpression          = "dp_convives" 
                UniqueName              = "dp_convives"
                HeaderText              = "Convives"
                DataType                = "System.Int32" 
                >
                <HeaderStyle HorizontalAlign="Right" /> 
                <ItemStyle   CssClass="monto_grid" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn 
                DataField               = "dp_prixs" 
                SortExpression          = "dp_prixs" 
                UniqueName              = "dp_prixs"
                HeaderText              = "Prix de la Paella"
                DataType                = "System.Decimal" 
                DataFormatString        = "{0:C2}"
                >
                <HeaderStyle HorizontalAlign="Right" /> 
                <ItemStyle   CssClass="monto_grid" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn 
                DataField               = "dp_prixs_unitaire" 
                SortExpression          = "dp_prixs_unitaire" 
                UniqueName              = "dp_prixs_unitaire"
                HeaderText              = "Prix unitaire "
                HeaderStyle-Width       = "120"
                DataType                = "System.Decimal" 
                DataFormatString        = "{0:C2}"
                >
                <HeaderStyle HorizontalAlign="Right" /> 
                <ItemStyle   CssClass="monto_grid" />
            </telerik:GridBoundColumn>
            <telerik:GridButtonColumn 
                ConfirmText             = "Cette action permet de supprimer le produit sélectionné de votre devis. <br/><br/>Etes-vous sûr ? <br/><br/>" 
                ButtonType              = "ImageButton"
                CommandName             = "Delete" 
                Text                    = "Supprimer ce produit" 
                UniqueName              = "DeleteColumn" 
                ConfirmDialogType       = "RadWindow"
                >
                <HeaderStyle Width="20px" />
                <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
            </telerik:GridButtonColumn>
        </Columns>
        <EditFormSettings>
            <EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType"></EditColumn>
        </EditFormSettings>
    </MasterTableView>
    <PagerStyle Mode="NextPrevAndNumeric" />
    <FilterMenu EnableTheming="True">
        <CollapseAnimation Duration="200" Type="OutQuint" />
    </FilterMenu>                        
</telerik:RadGrid>
So no problem here ...!

Then, I need to show the items found on the sessiondatasource and try the following(the code behind the .aspx is as below):
string query_str = "SELECT * FROM [devis] order by dp_key";
DataTable dt = GetDataTable(query_str);
RadGrid_devis_panel.DataSource = dt;
RadGrid_devis_panel.DataBind();
etapa_02.Alert("--> devis_rpt_PreRender : " + dt.Rows.Count);

I do not show any item (dt.Rows.Count = 0), as I can read data from the sessiondatasource?

Thanks in advance!
Jorge Saa-Gerbier

The code the  is as below: (the code behind the  is as below):

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 09 Feb 2011, 04:47 PM
Hello Jorge,

You can use the SessionDataSource control is just like any other DataSource control like the ASP:SqlDataSource control for instance. Therefore to bind the grid to it, you only need to assign the grid DataSourceID property and you should not set the grid DataSource and call DataBind for it explicitly.
Then to get the returned rows cound, you can handle the control Selected event.

Regards,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
General Discussions
Asked by
Jorge Saa-Gerbier
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or