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

Radgrid inside RadPageView client-side binding causes postback

2 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sumathi
Top achievements
Rank 1
Sumathi asked on 14 Apr 2015, 04:43 PM

Hi

I have a radgrid inside RadPageView. I have a submit button and uses jquery click event to retrieve data using wcf. I am getting data and able to bind it. After binding, some scroll event gets triggered and causes a postback. As I don't have any logic to retrieve data on the page postback, the grid is empty again.

How to stop the events from triggering...

Also, paging is enabled, but the grid displays all records at one shot which I believe causes the scrolling, but which one ?.

Here is my code snippet.

 

Default.aspx

$(document).ready(function () {
//alert('To Date Click');
$('#ctl00_ContentPlaceHolder1_btnSubmit').click(function () {

 var uri = "../Default.svc.cs/GetData";

var datival = "userId="+12345;

$.ajax({
url:uri+dataval,
type:'GET',
async:false,
dataType:"json",
contentType: "application/json;charset=utf-8",

error: function (XMLHttpRequest, textStatus, errorThrown) {
//$('#loading').hide();
alert(errorThrown);
alert(XMLHttpRequest.statusText);
alert(textStatus);
                        
                        return true;
},

success:function(data){
alert('Data retrieved:' + data);
var gridDealers = $find("<%=radGrid1.ClientID %>").get_masterTableView();
gridDealers.set_dataSource([]);
gridDealers.dataBind();
var gridData = data["DataGridList"];
gridDealers.set_dataSource(gridData);
gridDealers.dataBind();
                        
                        
                        }

}):

});

<telerik:RadTabStrip ID="RadTabStrip1" runat="server" Skin="Office2007" MultiPageID="RadMultiPage1"
SelectedIndex="0" >
<Tabs>
<telerik:RadTab Text="Inspection Report" Font-Bold="true" Font-Size="Small" runat="server"
Selected="True">
</telerik:RadTab>
</Tabs>
</telerik:RadTabStrip>
<telerik:RadMultiPage runat="server" ID="RadMultiPage1" SelectedIndex="0" ScrollBars="None">
<telerik:RadPageView runat="server" ID="RadPageView1">
<asp:Panel runat="server" ID="pnlTopRight" Width="100%">

<telerik:RadGrid ID="radGrid1" OnSortCommand="radGrid1_SortGrid"
runat="server" AutoGenerateColumns="False" Skin="Office2007"
AllowPaging="True" AllowSorting="True" PagerStyle-Mode="NextPrevAndNumeric"
OnNeedDataSource="radGrid1_NeedDataSource" onpageindexchanged="radGrid1_PageIndexChanged"
AllowFilteringByColumn="True" FilterItemStyle-Height="10px" onpagesizechanged="radGrid1_PageSizeChanged"
GroupPanelPosition="Top" ResolvedRenderMode="Classic" VirtualItemCount="10"
ExportSettings-OpenInNewWindow="true" ExportSettings-Excel-Format="Xlsx"
onitemdatabound="radGrid1_ItemDataBound1"
onhtmlexporting="radGrid1_Exporting">
<HeaderStyle Font-Bold="true" HorizontalAlign="Center" Font-Size="Smaller" Font-Names="Verdana" />
<ItemStyle Font-Size="Smaller"/>
<AlternatingItemStyle Font-Size="Smaller"/>
<ExportSettings Excel-Format="Xlsx" IgnorePaging="true"></ExportSettings>
<MasterTableView DataKeyNames="Code, ID">
<NoRecordsTemplate>
<div>
There are no records to display</div>
</NoRecordsTemplate>
<Columns>

    <telerik:GridBoundColumn .....>

     .......

    </telerik:GridBoundColumn>

</Columns>

</MasterTableView>
</telerik:RadGrid>
</telerik:RadPageView>
</telerik:RadMultiPage>

 

Default.svc.cs

public IList GetData(int userId)

{

    // process sql data and return list.

}

 

2 Answers, 1 is accepted

Sort by
0
Jaya
Top achievements
Rank 1
answered on 15 Apr 2015, 04:14 AM

Hi

Can you share your code zip format . Thats solve your issue some members.

0
Sumathi
Top achievements
Rank 1
answered on 15 Apr 2015, 02:08 PM

<%@ Page Language="C#" MasterPageFile="~/Master/SGSMasterPage.master" AutoEventWireup="true" CodeBehind="CPOClientSideBinding.aspx.cs" Inherits="CPO.SGSAuto.CPOClientSideBinding" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderHead" runat="server">
<script src="../JS/jquery-1.10.2.js"></script>
    <script src="../JS/jquery-ui-1.10.4.custom.js"></script>
    <script src="../js/bootstrap-maxlength.js" type="text/javascript"></script>
    <script src="../JS/linq.js"></script>
 <style type="text/css">



        .RadPicker TD
        {
            vertical-align:Top !important;
        }                

       .middelpenal .page .container
       {
           padding-bottom:4px !important;                     
       }

       .sitemapContainer
       {
            background:#fff;
       border-bottom:12px solid #c1c1c1;
       padding:10px 0px;
       position:relative;
       height:8px;
       }

        </style>

</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<asp:ScriptManager runat="server" ID="scriptManager"></asp:ScriptManager>
    <div class="header">
        <div class="container">

            <div class="pull-left">                                    
                    <asp:Image ID="imgHonda" runat="server" ImageUrl="~/Images/Honda_CPO_Logo.png" Width="113" Height="55" alt=""/>
            </div>
            <div class="pull-left sgslogo" style="padding-left: 15px">                                    
                    <asp:Image ID="imgAcura" runat="server" ImageUrl="~/Images/Acura_logo.jpg"  Width="113" Height="55" alt=""/>
            </div>
            <div class="pull-right">
                <a href="#">
                    <img src="../images/logo.png" width="113" height="55" alt=""></a>
            </div>


        </div>
    </div>

    <%--<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">--%>
        <script type="text/javascript">
            $(document).ready(function () {
                //alert('To Date Click');
                $('#ctl00_ContentPlaceHolder1_btnSubmit').click(function () {
                    //alert('To Date Click');
                    $('#loading').show();
                    var validationMessage = '';
                    var valid = true;
                    var wFromDate = $find("<%=radFromDate.ClientID%>").get_selectedDate();
                    var wToDate = $find("<%=radToDate.ClientID %>").get_selectedDate();
                    var diff = dateDiff(wFromDate, wToDate);

                    if (wFromDate && wToDate) {

                        if (diff < 0) {
                            validationMessage += "<p>From date must be smaller than To date.</p>";
                            valid = false;
                        }
                    }
                    else {
                        validationMessage += "<p>Please select From and To dates.</p>";
                        valid = false;
                    }
                    if (!valid) {
                        //alert(validationMessage);
                        $('#lblPopupMessage').html(validationMessage);
                        //$('#PopupAlertMessage').modal();
                        $('#PopupAlertMessage').dialog({
                            minHeight: 'auto',
                            position: 'center',
                            modal: true
                        });
                        return false;
                    }
                    else {

                        $('#loading').show();
                        var sessionid = <%=sessionUserID %>;

                        wFromDate = $find("<%=radFromDate.ClientID%>")._dateInput._displayText;
                        wToDate = $find("<%=radToDate.ClientID %>")._dateInput._displayText;

                        var uri = "../Service/CPOServices.svc/GetDealerGridData";
                        var dataval = "?userId=" + sessionid + "&startDate=" + wFromDate + "&endDate=" + wToDate;

                        alert(uri);

                        $.ajax({
                        url:uri+dataval,
                        type:'GET',
                        async:false,
                        dataType:"json",
                        contentType: "application/json;charset=utf-8",

                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            //$('#loading').hide();
                            alert(errorThrown);
                            alert(XMLHttpRequest.statusText);
                            alert(textStatus);
                        $('#loading').hide();
                        return true;
                        },

                        success:function(data){
                        alert('Data retrieved:' + data);
                        var gridDealers = $find("<%=radGridDealers.ClientID %>").get_masterTableView();
                        gridDealers.set_dataSource([]);
                        gridDealers.dataBind();
                        var gridData = data["DealerGridList"];
                        gridDealers.set_dataSource(gridData);
                        gridDealers.dataBind();
                        $('#loading').hide();

                        }

                        });
                    }

                });

            });

            //<![CDATA[
            function dateDiff(startDate, endDate) {
                if (endDate && startDate) //make sure we don't call .getTime() on a null
                    return (endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24);
                return "You must complete both dates!";
            }

            $('#loading').hide();
            function validateDate(sender, eventArgs) {
                var msg = "";p
                var fromDate = $find("<%=radFromDate.ClientID%>");
                var toDate = $find("<%=radToDate.ClientID%>");

                fromDate.set_value(fromDate.get_value().trim());
                toDate.set_value(lastName.get_value().trim());

                if (fromDate.get_value().length < 2) {
                    fromDate.focus();
                    msg = "\nFirst name is required (minimum 2 chars).";
                }

                if (toDate.get_value().length < 2) {
                    if (msg == "") {
                        lastName.focus();
                    }
                    msg += "\nTo Date is required (minimum 2 chars).";
                }
            }
            function OnDealerTreeNodeChecked(sender, args) {
                var node = args.get_node();
                //alert(node);
                for (var i = 0; i < node.get_allNodes().length; i++) {
                    var childNode = node.get_allNodes()[i];
                    if (node.get_checked()) {
                        childNode.set_checked(true);
                    }
                    else {
                        childNode.set_checked(false);
                    }
                }
            }

            function radio_BetweenDatesCheckedChanged(sender, args) {
                var fromDate = $find("<%=radFromDate.ClientID%>");
                var toDate = $find("<%=radToDate.ClientID %>");
                if (args.get_checked()) {
                    fromDate.set_enabled(true);
                    toDate.set_enabled(true);
                }
                else {
                    fromDate.set_enabled(false);
                    toDate.set_enabled(false);
                }
            }
            var fromDate;
            var toDate;
            // necessary to disable the days more than 370 on client-side navigation
            function fromdateInput_DateChanged(calendarInstance, args) {
                // convert the date-triplet to a javascript date
                // we need Date.getDay() method to determine 
                // which days should be disabled (e.g. every Saturday (day = 6) and Sunday (day = 0))
                fromDate = calendarInstance._displayText;
                var newDate = new Date(args.get_newDate());
                toDate = $find("<%=radToDate.ClientID %>");

                toDate.set_minDate(newDate);
                toDate.set_maxDate(new Date(newDate.setDate(newDate.getDate() + 370)));
            }

            function toDate_Selected(sender, args) {

            }

            var treeUncheckStatus = false;
            function SearchComboSelectedIndexChanged(sender, eventArgs) {
                var item = eventArgs.get_item();
                var itemText = item.get_text();
                var textSearchType = $find("<%=txtSearchType.ClientID %>");
                //var textSearchValue = $find("<%=txtSearchValue.ClientID %>");
                //var dispText = $find("<%=displayText.ClientID %>");
                var radTree = $find("<%=radTreeViewDealer.ClientID %>");

                var divElementText = document.getElementById('divTextBox');
                var divElementLabel = document.getElementById('divLabel');

                if (itemText == "Hierarchy") {
                    if (divElementText.style.display == 'block') {
                        divElementText.style.display = 'none';
                    }
                    if (divElementLabel.style.display == 'none') {
                        divElementLabel.style.display = 'block';
                    }

                    radTree.set_enabled(true);

                    treeUncheckStatus = false;
                }
                else {
                    if (divElementText.style.display == 'none') {
                        divElementText.style.display = 'block';
                    }
                    if (divElementLabel.style.display == 'block') {
                        divElementLabel.style.display = 'none';
                    }
                    itemText += ":";
                    textSearchType.set_value(itemText);
                    if (treeUncheckStatus == false) {
                        radTree.uncheckAllNodes();
                        treeUncheckStatus = true;
                    }
                    radTree.set_enabled(false);
                }
            }

            function mngRequestStarted(ajaxManager, eventArgs) {
                if (eventArgs.EventTarget == "btnExcelExport")
                    eventArgs.set_enableAjax(false);
            }

            //]]>
        </script>
    <%--</telerik:RadCodeBlock>--%>
    <div class="middelpenal">
        <div class="page">
         <div  class="sitemapContainer" id="pnlSiteMap" runat="server">
         <table style="width:100%">
         <tr>
            <td style="width:30%">
                <asp:LinkButton runat="server" Visible="false" style="line-height:5px !important;padding-left:35px;font: normal bold 15px Segoe UI, Arial, Helvetica, sans-serif;color:#00156e" ID="lnkbtnHome" Text="Home" OnClick="lnkbtnHome_OnClick"></asp:LinkButton>
            </td>
            <td style="width:45%">
            </td>
            <td style="width:25%; text-align:center;">
                <asp:LinkButton runat="server" style="line-height:5px !important;padding-left:35px; font: normal bold 15px Segoe UI, Arial, Helvetica, sans-serif; vertical-align:top;color:#00156e" ID="lnkbtnLogout" Text="Logout" OnClick="lnkbtnLogout_Click"></asp:LinkButton>
            </td>
         </tr>
         </table>

         </div>
            <div class="container">
                <table style="width: 100%; padding-bottom: 2px;">
                    <tr>
                        <td style="width: 30%; border-color: #8db4e3; border-style: solid; border-width: 1px;
                            vertical-align: top;">
                            <%--<br />--%>
                            <asp:Panel runat="server" ID="pnlTopLeft" Width="100%" Style="padding-top: 10px; height:62px;">
                                <fieldset>
                                    <%--<legend style="font-size: 12px; font-weight: bold; background-color: Orange; color: White;
                                        font-family: Verdana"></legend>--%>
                                    <table>
                                        <%--<tr>
                                            <td>
                                                <telerik:RadButton runat="server" ID="radioHonda" Text="Honda" ToggleType="Radio"
                                                    Font-Bold="true" ButtonType="ToggleButton" GroupName="Division" AutoPostBack="true" Value="A"
                                                    CausesValidation="False" OnCheckedChanged="radioDealer_CheckedChanged" Skin="Office2007">
                                                </telerik:RadButton>
                                            </td>
                                            <td>
                                                <telerik:RadButton runat="server" ID="radioAcura" Text="Acura" ToggleType="Radio"
                                                    Font-Bold="true" ButtonType="ToggleButton" GroupName="Division" AutoPostBack="true"  Value="B"
                                                    CausesValidation="False" OnCheckedChanged="radioDealer_CheckedChanged" Skin="Office2007">
                                                </telerik:RadButton>
                                            </td>
                                        </tr>--%>
                                        <tr>
                                            <td align="left">
                                                <telerik:RadTextBox ID="txtSearchLabel" runat="server" Enabled="false" Font-Bold="true" 
                                                        SkinID="Office2007" Width="100px" Text="Search By:">
                                                        <EmptyMessageStyle Resize="None" />
                                                        <ReadOnlyStyle Resize="None" />
                                                        <FocusedStyle Resize="None" />
                                                        <DisabledStyle BorderColor="White" BorderStyle="None" HorizontalAlign="Right" 
                                                            Resize="None" />
                                                        <InvalidStyle Resize="None" />
                                                        <HoveredStyle Resize="None" />
                                                        <EnabledStyle Resize="None" />
                                                    </telerik:RadTextBox>
                                                <telerik:RadComboBox ID="cboSearchParams" runat="server" Skin="Office2007" 
                                                    OnClientSelectedIndexChanged="SearchComboSelectedIndexChanged" 
                                                    Width="100px">
                                                    <Items>
                                                        <telerik:RadComboBoxItem Text="Hierarchy" Value="1" Selected="true" />
                                                        <telerik:RadComboBoxItem Text="Dealer Code" Value="2" />
                                                        <telerik:RadComboBoxItem Text="Order #" Value="3" />
                                                    </Items>
                                                </telerik:RadComboBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="left">
                                                <div id="divTextBox"  style="display:none">
                                                    <telerik:RadTextBox ID="txtSearchType" runat="server" Enabled="false" Font-Bold="true" 
                                                        SkinID="Office2007" Width="100px">
                                                        <EmptyMessageStyle Resize="None" />
                                                        <ReadOnlyStyle Resize="None" />
                                                        <FocusedStyle Resize="None" />
                                                        <DisabledStyle BorderColor="White" BorderStyle="None" HorizontalAlign="Right" 
                                                            Resize="None" />
                                                        <InvalidStyle Resize="None" />
                                                        <HoveredStyle Resize="None" />
                                                        <EnabledStyle Resize="None" />
                                                    </telerik:RadTextBox>
                                                    <telerik:RadTextBox ID="txtSearchValue" runat="server" Skin="Office2007" Width="100px"></telerik:RadTextBox>
                                                    <br />
                                                    <br />
                                                </div>
                                                <div id="divLabel" style="display:block">
                                                    <asp:Label ID="displayText" runat="server" Text="Please select desired level in following tree by clicking on the check-box (<img src='Images/emptycheckbox.png'/>). You may expand a level by clicking on (+)"></asp:Label>
                                                </div>    
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2"></td>
                                        </tr>
                                    </table>
                                </fieldset>
                            </asp:Panel>
                            <br />
                            <asp:Panel ID="bottomLeft" runat="server" Height="395px" BorderColor="#8db4e3" BorderWidth="1px"
                                BorderStyle="Solid" ScrollBars="Vertical">
                                <telerik:RadTreeView ID="radTreeViewDealer" runat="server" Skin="Office2007" 
                                    ClientIDMode="AutoID" CheckBoxes="true" 
                                    CheckChildNodes="true" TriStateCheckBoxes="true">
                                    <DataBindings>
                                        <telerik:RadTreeNodeBinding Expanded="True"></telerik:RadTreeNodeBinding>
                                    </DataBindings>
                                </telerik:RadTreeView>
                            </asp:Panel>
                        </td>
                        <td style="width: 70%; border-color: #8db4e3; border-style: solid; border-width: 1px;
                            border-right: 2px solid; vertical-align: top">
                            <telerik:RadTabStrip ID="RadTabStrip1" runat="server" Skin="Office2007" MultiPageID="RadMultiPage1"
                                SelectedIndex="0" PerTabScrolling="false" ScrollChildren="false">
                                <Tabs>
                                    <telerik:RadTab Text="Inspection Report" Font-Bold="true" Font-Size="Small" runat="server"
                                        Selected="True">
                                    </telerik:RadTab>
                                </Tabs>
                            </telerik:RadTabStrip>
                            <telerik:RadMultiPage runat="server" ID="RadMultiPage1" SelectedIndex="0" ScrollBars="None">
                                <telerik:RadPageView runat="server" ID="RadPageView1">
                                    <asp:Panel runat="server" ID="pnlTopRight" Width="100%">
                                        <fieldset>
                                            <legend style="font-size: 12px; font-weight: bold; background-color: Orange; color: White;
                                                font-family: Verdana"></legend>
                                                <br />
                                            <table width="100%" cellpadding="0" cellspacing="0">
                                                <tr>
                                                    <td colspan="2"></td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <telerik:RadButton runat="server" ID="radbtn7Days" Text="Last 7 Days" ToggleType="Radio" Value="7Days"
                                                            Font-Bold="true" ButtonType="ToggleButton" GroupName="Dates" AutoPostBack="false"
                                                            CausesValidation="False" Skin="Office2007">
                                                        </telerik:RadButton>
                                                        &nbsp;&nbsp;&nbsp;
                                                        <telerik:RadButton runat="server" ID="radbtn30Days" Text="Last 30 Days" ToggleType="Radio" Value="30Days"
                                                            Font-Bold="true" ButtonType="ToggleButton" Checked="true" GroupName="Dates" AutoPostBack="false"
                                                            CausesValidation="False" Skin="Office2007">
                                                        </telerik:RadButton>
                                                        &nbsp;&nbsp;&nbsp;
                                                    <%--</td>
                                                    <td>--%>
                                                        <telerik:RadButton runat="server" ID="radbtnBetDays" Text="Between" ToggleType="Radio" Value="Between"
                                                            Font-Bold="true" ButtonType="ToggleButton" GroupName="Dates" AutoPostBack="false" CausesValidation="False" 
                                                            Skin="Office2007" OnClientCheckedChanged="radio_BetweenDatesCheckedChanged" >
                                                        </telerik:RadButton>
                                                        &nbsp;&nbsp;&nbsp;
                                                    <%--</td>
                                                    <td style="padding-bottom: 10px">--%>
                                                        <telerik:RadDatePicker ID="radFromDate" runat="server" Skin="Office2007"
                                                            Width="100px" Culture="en-US" ResolvedRenderMode="Classic" Enabled="false">
                                                            <Calendar Skin="Office2007" runat="server" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False"
                                                                ViewSelectorText="x">
                                                            </Calendar>
                                                            <DateInput ID="radFromDateInput" DateFormat="M/d/yyyy" runat="server" DisplayDateFormat="M/d/yyyy" Height="14px"
                                                                LabelWidth="" OnClientDateChanged="fromdateInput_DateChanged">
                                                                <ClientEvents OnValueChanged="fromdateInput_DateChanged" />
                                                            </DateInput>
                                                            <DatePopupButton HoverImageUrl="" ImageUrl="" />
                                                        </telerik:RadDatePicker>
                                                        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                        <%--</td>
                                                            <td>--%>
                                                        <telerik:RadDatePicker ID="radToDate" runat="server" Skin="Office2007" 
                                                            Width="100px" Culture="en-US" Enabled="false">
                                                            <Calendar ID="Calendar1" Skin="Office2007" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False"
                                                                ViewSelectorText="x" runat="server" >
                                                            </Calendar>
                                                            <DateInput ID="radToDateInput" DateFormat="M/d/yyyy" runat="server" DisplayDateFormat="M/d/yyyy" Height="14px"
                                                                LabelWidth="" >
                                                            </DateInput>
                                                             <DatePopupButton HoverImageUrl="" ImageUrl="" />
                                                             <ClientEvents OnDateSelected="toDate_Selected" />
                                                        </telerik:RadDatePicker>
                                                        &nbsp;&nbsp;&nbsp;
                                                    </td>
                                                    <td align="right">
                                                        <telerik:RadButton ID="btnSubmit" runat="server" Text="Submit" Skin="Office2007">
                                                        </telerik:RadButton>
                                                    </td>
                                                </tr>
                                            </table>
                                        </fieldset>
                                    </asp:Panel>
                                  <%--  <br />--%>
                                    <table width="100%">
                                    <tr>
                                        <td style="width:90%"><asp:Label runat="server" ID="lblUserMessage" Text="Click on <b>Dealer Code</b> to view Report" Font-Size="Smaller" SkinID="Office2007"></asp:Label></td>
                                        <td style="width:10%" align="right" ><telerik:RadButton ID="btnExcelExport" runat="server" Text="Export To Excel" Skin="Office2007" OnClick="btnExcelExport_Click"></telerik:RadButton></td>
                                    </tr>
                                    </table>

                                  <%--  <br />--%>
                                    <telerik:RadGrid ID="radGridDealers" OnSortCommand="radGridDealers_SortGrid" 
                                        runat="server" AutoGenerateColumns="False" Skin="Office2007"
                                        AllowPaging="True" AllowSorting="True" PagerStyle-Mode="NextPrevAndNumeric"
                                        OnNeedDataSource="radGridDealers_NeedDataSource" onpageindexchanged="radGridDealers_PageIndexChanged" 
                                        AllowFilteringByColumn="True" FilterItemStyle-Height="10px" onpagesizechanged="radGridDealers_PageSizeChanged" 
                                        GroupPanelPosition="Top" ResolvedRenderMode="Classic" VirtualItemCount="10" 
                                        ExportSettings-OpenInNewWindow="true" ExportSettings-Excel-Format="Xlsx" 
                                        onitemdatabound="radGridDealers_ItemDataBound1" 
                                        onhtmlexporting="radGridDealers_Exporting">
                                        <HeaderStyle Font-Bold="true" HorizontalAlign="Center" Font-Size="Smaller" Font-Names="Verdana" />
                                        <ItemStyle Font-Size="Smaller"/>
                                        <AlternatingItemStyle Font-Size="Smaller"/>
                                        <ExportSettings Excel-Format="Xlsx" IgnorePaging="true"></ExportSettings>
                                        <MasterTableView DataKeyNames="Dealer_Code, Assignment_ID">
                                            <NoRecordsTemplate>
                                                <div>
                                                    There are no records to display</div>
                                            </NoRecordsTemplate>
                                            <Columns>
                                                <telerik:GridBoundColumn DataField="Dealer_Type" ItemStyle-Width="40px" AllowSorting="true" SortExpression="Dealer_Type" AllowFiltering="false"
                                                    UniqueName="DivisionCode" HeaderText="Division">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn DataField="Zone_Code" ItemStyle-Width="20px" AllowSorting="true" AllowFiltering="false" SortExpression="Zone_Code"
                                                    UniqueName="ZoneCode" HeaderText="Zone">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn DataField="SalesDistrictCode" ItemStyle-Width="20px" AllowSorting="true" AllowFiltering="false" SortExpression="SalesDistrictCode"
                                                    UniqueName="SalesDistrictCode" HeaderText="District">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridHyperLinkColumn DataNavigateUrlFields="Link_Code" UniqueName="Dealer" AllowFiltering="false"
                                                    Target="blank" HeaderText="Dealer Code" ItemStyle-Width="30px" DataNavigateUrlFormatString="CPOInspectionReport.aspx?LINK={0}&MID=14661"
                                                    DataTextField="Dealer_Code">
                                                </telerik:GridHyperLinkColumn>
                                                <telerik:GridBoundColumn DataField="Dealer_Name" AllowSorting="true" AllowFiltering="false" UniqueName="DealerName" SortExpression="Dealer_Name"
                                                    HeaderText="Dealer Name">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn DataField="Audit_Date" AllowSorting="true" AllowFiltering="false" SortExpression="Audit_Date" UniqueName="AuditDate"
                                                    HeaderText="Inspection Date" ItemStyle-Width="60px" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn DataField="VehiclesInspected" AllowSorting="true" AllowFiltering="false" UniqueName="VehiclesInspected"
                                                    HeaderText="# of Vehicles Inspected" SortExpression="VehiclesInspected" ItemStyle-HorizontalAlign="Right"  ItemStyle-Width="80px">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn DataField="VehiclesCompliant" AllowSorting="true" AllowFiltering="false" UniqueName="VehiclesCompliant"
                                                    HeaderText="# of Vehicles Compliant" SortExpression="VehiclesCompliant" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="80px">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn DataField="ComplianceStatus" SortExpression="ComplianceStatus" AllowFiltering="true" AllowSorting="true" UniqueName="ComplianceStatus"
                                                    HeaderText="Compliance Status" ItemStyle-Width="80px">
                                                    <FilterTemplate>
                                                        <telerik:RadComboBox ID="ComplianceCombo" Width="100px" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("ComplianceStatus").CurrentFilterValue %>'
                                                            runat="server" OnClientSelectedIndexChanged="ComplianceStatusComboIndexChanged" OnSelectedIndexChanged="ComplianceStatusIndexChanged" >
                                                            <Items>
                                                                <telerik:RadComboBoxItem Text="All" Value="All" />
                                                                <telerik:RadComboBoxItem Text="Compliant" Value="Compliant" ForeColor="Red" />
                                                                <telerik:RadComboBoxItem Text="Non-Compliant" Value="Non-Compliant" ForeColor="Red" />
                                                            </Items>
                                                        </telerik:RadComboBox>
                                                        <telerik:RadScriptBlock ID="RadScriptBlock4" runat="server">
                                                            <script type="text/javascript">
                                                                function ComplianceStatusComboIndexChanged(sender, args) {
                                                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                                                    var filterVal = args.get_item().get_value();

                                                                    if (filterVal == "All") {
                                                                        tableView.filter("ComplianceStatus", filterVal, "NoFilter");
                                                                    }
                                                                    else {
                                                                        tableView.filter("ComplianceStatus", filterVal, "EqualTo");
                                                                    }
                                                                }
                                                            </script>
                                                        </telerik:RadScriptBlock>
                                                    </FilterTemplate>
                                                </telerik:GridBoundColumn>
                                            </Columns>
                                        </MasterTableView>
                                    </telerik:RadGrid>
                                </telerik:RadPageView>
                            </telerik:RadMultiPage>
                        </td>
                    </tr>
                </table>
                <br />
                <br />

                <div class="footer">

                 <table width="100%">
                        <tr>
                            <td style="width:35%">
                                <div style="float: left; padding-left: 15px; font-size: 11px; margin-top: 5px; margin-bottom: 5px;">
                                    <asp:Label runat="server" ID="lblUserName" /></div>
                            </td>
                            <td style="width:30%"></td>
                            <td style="width:35%">
                                <div style="font-size: 11px; margin-top: 5px; margin-bottom: 5px;float: right;padding-right: 15px;">
                                    <asp:LinkButton OnClick="lnkSecurityProfile_Click" Text="My Security Profile" runat="server" ID="lnkSecurityProfile" /></div>
                            </td>
                            <%--<td>
                                <p>
                                    © 1995 - 2014 SGS SA
                                </p>
                            </td>--%>
                            <%--<td style="width:35%">
                                <div style="float: right;font-size: 11px; padding-right: 15px; font-size: 11px;">
                                    <asp:LinkButton runat="server" ID="lnkbtnLogout" Text="Logout" OnClick="lnkbtnLogout_Click"></asp:LinkButton>
                                    </div>
                            </td>--%>
                        </tr>
                    </table>    
                </div>
            </div>
        </div>
    </div>
    <div id="loading">
        <img id="loading-image" src="../Images/loadinfo.net.gif" alt="Loading" height="48px" width="48px" />
    </div>
    <div id="PopupAlertMessage" title="Information Alert" style="display: none;">
        <label id="lblPopupMessage"></label>

            <p style="padding-top: 10px;">
                <input id="btnOkPopup" value="Ok" type="button" class="btn" style="padding: 5px 20px; height: auto;" />
            </p>
    </div>

</asp:Content>

The code-behind

 

namespace CPO.SGSAuto
{
    public partial class CPOClientSideBinding : System.Web.UI.Page
    {
        // test user ids
        // 9365, 9771, 9772, 9773

        public string lstString = "";
        public string sessionUserID = "";
        public static DataSet dsDashBoardData;

        bool IsHondaAcuraRadioButtonClicked = false;
        bool _exporting = false;

        List<DealerGridData> lstGridData = new List<DealerGridData>();
        List<DealerTreeData> lstTreeData = new List<DealerTreeData>();

        List<string> SelectedDealerCodesList = new List<string>();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["EnU"] == null)
            {
                Session["SessionExpired"] = true;
                Response.Redirect("Login.aspx");
                return;
            }

            if (Session["LevelNumberCnt"] != null)
            {
                if (Convert.ToInt32(Session["LevelNumberCnt"].ToString()) > 1)
                {
                    //pnlSiteMap.Visible = true;
                    lnkbtnHome.Visible = true;
                }
                else
                {
                    //pnlSiteMap.Visible = false;
                    lnkbtnHome.Visible = false;
                }
            }

            SGSCryptoGraphy.SGSCrypto oCrypto = new SGSCryptoGraphy.SGSCrypto();
            sessionUserID = oCrypto.DecryptMessage(Session["EnU"].ToString());
            oCrypto = null;
            //sessionUserID = "10359"; //Brian_Butts

            // temporary - for testing
            if (Session["UserName"] != null)
            {
                lblUserName.Text = "Welcome " + Session["UserName"].ToString() + "!";
            }

            if (!Page.IsPostBack)
            {
                // Get Dealer Tree data
                GetDealerTreeData();

                //Get Recordset
                //GetDealerData();

                //Populate Tree view
                PopulateTreeView();

                //Populate Grid
                radGridDealers.DataSource = new List<ClientDealerGridDTO>();
                radGridDealers.MasterTableView.VirtualItemCount = 10;
            }
            else
            {
                // Moving this piece of code to Search button click. - 3/15/2015

                //Get the selected dealer codes from the treeview dealer nodes. This list is being used 
                //in radGridDealers_NeedDataSource event to filter records for selected dealers
                SelectedDealerCodesList = (from DealerCode in radTreeViewDealer.CheckedNodes.Where(p => p.Level == 3)
                                           select DealerCode.Value.Substring(0, 6)).ToList();
                //GetDealerData();
                Response.Flush();
                Response.Clear();

            }
            
        }

        private void GetDealerTreeData()
        {
            DBHondaCPO DBHondaCPO = new DBHondaCPO();
            try
            {
                dsDashBoardData = new DataSet();
                dsDashBoardData = DBHondaCPO.GetHondaDealerTreeData(sessionUserID, "%%%%%%%%%%%");
                DBHondaCPO = null;

                //Add Honda and Acura nodes for first load
                bool AddHondaRoot = true;
                bool AddAcuraRoot = true;

                //if (radioHonda.Checked == true)
                //{
                //    AddAcuraRoot = false;
                //}

                //if (radioAcura.Checked == true)
                //{
                //    AddHondaRoot = false;
                //}

                if (AddHondaRoot)
                {
                    //Add Honda Zones
                    var HondaZones = (from DataRow dr in dsDashBoardData.Tables[0].AsEnumerable().Distinct()
                                      where (dr["Division_Code"].ToString().Trim() == "A")
                                      select new DealerTreeData()
                                      {
                                          ID = "A" + dr.Field<string>("Zone_Code"),
                                          ParentID = "-100",
                                          Name = dr.Field<string>("Zone_Name"),
                                          //CheckFlag = null,
                                          DivisionCode = "A",
                                      }).GroupBy(x => x.ID).Select(g => g.First());

                    lstTreeData.AddRange(HondaZones);

                    //Add Honda District
                    foreach (DealerTreeData Zone in HondaZones)
                    {
                        var HondaDistricts = (from DataRow drDist in dsDashBoardData.Tables[0].AsEnumerable().Distinct()
                                              where ((drDist["Division_Code"].ToString().Trim() == "A") && ("A" + drDist["Zone_Code"].ToString() == Zone.ID))
                                              select new DealerTreeData()
                                              {
                                                  ID = "A" + drDist.Field<string>("District_Code"),
                                                  ParentID = Zone.ID,
                                                  Name = drDist.Field<string>("District_Code"),
                                                  //CheckFlag = null,
                                                  DivisionCode = "A",
                                              }).GroupBy(y => y.ID).Select(g => g.First());

                        lstTreeData.AddRange(HondaDistricts);

                        foreach (DealerTreeData Dist in HondaDistricts)
                        {
                            lstTreeData.AddRange((from DataRow drDealer in dsDashBoardData.Tables[0].AsEnumerable().Distinct()
                                                  where ((drDealer["Division_Code"].ToString().Trim() == "A")
                                                  && (("A" + drDealer["Zone_Code"].ToString()).StartsWith(Zone.ID))
                                                  && ("A" + drDealer["District_Code"].ToString()) == Dist.ID)
                                                  //&& drDealer["CheckFlag"].ToString().Trim() == "1")
                                                  select new DealerTreeData()
                                                  {
                                                      ID = drDealer.Field<string>("Dealer_Name"),
                                                      ParentID = Dist.ID,
                                                      Name = drDealer.Field<string>("Dealer_Name"),
                                                      //CheckFlag = Convert.ToInt32(drDealer["CheckFlag"]),
                                                      DivisionCode = "A",
                                                  }).GroupBy(d => d.ID).Select(g => g.First()));
                        }
                    }

                    if (HondaZones.Count() == 0)
                    {
                        //imgHonda.Visible = false;
                        //radioHonda.Enabled = false;
                    }
                    else
                    {
                        //DealerTreeData RootHonda = new DealerTreeData() { ID = "-100", ParentID = null, Name = "Honda", CheckFlag = null, DivisionCode = "A" };
                        DealerTreeData RootHonda = new DealerTreeData() { ID = "-100", ParentID = null, Name = "Honda", DivisionCode = "A" };
                        lstTreeData.Add(RootHonda);
                    }
                }

                if (AddAcuraRoot)
                {

                    //Add Acura Zones
                    var AcuraZones = (from DataRow dr in dsDashBoardData.Tables[0].AsEnumerable().Distinct()
                                      where (dr["Division_Code"].ToString().Trim() == "B")
                                      select new DealerTreeData()
                                      {
                                          ID = "B" + dr.Field<string>("Zone_Code"),
                                          ParentID = "-200",
                                          Name = dr.Field<string>("Zone_Name"),
                                          //CheckFlag = null,
                                          DivisionCode = "B",
                                      }).GroupBy(x => x.ID).Select(g => g.First());

                    lstTreeData.AddRange(AcuraZones);

                    //Add Acura District
                    foreach (DealerTreeData Zone in AcuraZones)
                    {
                        var AcuraDistricts = (from DataRow drDist in dsDashBoardData.Tables[0].AsEnumerable().Distinct()
                                              where ((drDist["Division_Code"].ToString().Trim() == "B") && ("B" + drDist["Zone_Code"].ToString() == Zone.ID))
                                              select new DealerTreeData()
                                              {
                                                  ID = "B" + drDist.Field<string>("District_Code"),
                                                  ParentID = Zone.ID,
                                                  Name = drDist.Field<string>("District_Code"),
                                                  //CheckFlag = null,
                                                  DivisionCode = "B",
                                              }).GroupBy(y => y.ID).Select(g => g.First());

                        lstTreeData.AddRange(AcuraDistricts);

                        foreach (DealerTreeData Dist in AcuraDistricts)
                        {
                            lstTreeData.AddRange((from DataRow drDealer in dsDashBoardData.Tables[0].AsEnumerable().Distinct()
                                                  where ((drDealer["Division_Code"].ToString().Trim() == "B")
                                                  && (("B" + drDealer["Zone_Code"].ToString()).StartsWith(Zone.ID))
                                                  && ("B" + drDealer["District_Code"].ToString()) == Dist.ID)
                                                  //&& drDealer["CheckFlag"].ToString().Trim() == "1")
                                                  select new DealerTreeData()
                                                  {
                                                      ID = drDealer.Field<string>("Dealer_Name"),
                                                      ParentID = Dist.ID,
                                                      Name = drDealer.Field<string>("Dealer_Name"),
                                                      //CheckFlag = Convert.ToInt32(drDealer["CheckFlag"]),
                                                      DivisionCode = "B",
                                                  }).GroupBy(d => d.ID).Select(g => g.First()));
                        }
                    }

                    if (AcuraZones.Count() == 0)
                    {
                        imgAcura.Visible = false;
                        //radioAcura.Enabled = false;
                    }
                    else
                    {
                        //DealerTreeData RootAcura = new DealerTreeData() { ID = "-200", ParentID = null, Name = "Acura", CheckFlag = null, DivisionCode = "B" };
                        DealerTreeData RootAcura = new DealerTreeData() { ID = "-200", ParentID = null, Name = "Acura", DivisionCode = "B" };
                        lstTreeData.Add(RootAcura);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

}

 

 

IService.cs

namespace CPO.SGSAuto.Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "ICPOServices" in both code and config file together.
    [ServiceContract]
    public interface ICPOServices
    {

        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetDealerGridData?userId={USERID}&startDate={STARTDATE}&endDate={ENDDATE}")]
        DealerGridListDTO GetDealerGridData(string userId, string startDate, string endDate);
    }
}

Service.svc.cs

namespace CPO.SGSAuto.Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "CPOServices" in code, svc and config file together.
    public class CPOServices : ICPOServices
    {
        public string lstString = "";
        public string sessionUserID = "";
        public static DataSet dsDashBoardData;


        public DealerGridListDTO GetDealerGridData(string userId, string startDate, string endDate)
        {
            DealerGridListDTO clientDealerGridList = new DealerGridListDTO();
            clientDealerGridList.DealerGridList = new List<ClientDealerGridDTO>();
            DB DBHondaCPO = new DB();
            try
            {
                DateTime dtStartDate = DateTime.Parse(startDate);
                DateTime dtEndDate = DateTime.Parse(endDate);

                string DealerCode = "", DivisionCode = "";
                dsDashBoardData = DB.GetHondaDashboardData(userId, "", dtStartDate, dtEndDate, null, null);
                for (int i = 0; i < dsDashBoardData.Tables[0].Rows.Count; i++)
                {
                    ClientDealerGridDTO dealerData = new ClientDealerGridDTO();

                    DealerCode = dsDashBoardData.Tables[0].Rows[i]["Dealer_Code"].ToString().Trim();
                    DivisionCode = dsDashBoardData.Tables[0].Rows[i]["Division_Code"].ToString().Trim();
                    dealerData.Dealer_Type = dsDashBoardData.Tables[0].Rows[i]["Dealer_Type"].ToString().Trim();
                    dealerData.Dealer_Name = dsDashBoardData.Tables[0].Rows[i]["Dealer_Name"].ToString().Trim();
                    dealerData.SalesDistrictCode = dsDashBoardData.Tables[0].Rows[i]["District_Code"].ToString().Trim();
                    dealerData.Division_Code = DivisionCode;
                    dealerData.ZonalDistrictCode = dsDashBoardData.Tables[0].Rows[i]["DistrictCode"].ToString().Trim();
                    dealerData.Zone_Code = dsDashBoardData.Tables[0].Rows[i]["Zone_Code"].ToString().Trim();
                    dealerData.Audit_Date = Convert.ToDateTime(dsDashBoardData.Tables[0].Rows[i]["Audit_Date"]);
                    dealerData.VehiclesInspected = Int32.Parse(dsDashBoardData.Tables[0].Rows[i]["VehiclesInspected"].ToString());
                    dealerData.VehiclesCompliant = Int32.Parse(dsDashBoardData.Tables[0].Rows[i]["VehiclesCompliant"].ToString());
                    dealerData.ComplianceStatus = dsDashBoardData.Tables[0].Rows[i]["ComplianceStatus"].ToString().Trim();
                    dealerData.Link_Code = dsDashBoardData.Tables[0].Rows[i]["Link_Code"].ToString().Trim();
                    clientDealerGridList.DealerGridList.Add(dealerData);
                }

            }
            catch (Exception ex)
            {
            }

            return clientDealerGridList;
        }
    }
}

 

Web.config

<system.serviceModel>
    <services>
      <service name="CPO.SGSAuto.Service.CPOServices" behaviorConfiguration="cposimplerest" >
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:65534/Service/CPOService.svc"/>
          </baseAddresses>
        </host>
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />

        <endpoint address="" binding="webHttpBinding" contract="CPO.SGSAuto.Service.ICPOServices" behaviorConfiguration="simplerest" bindingConfiguration="nonsecure"  />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="cposimplerest">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="simplerest" >
          <webHttp defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Json" faultExceptionEnabled="true" helpEnabled="true"></webHttp>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding name="nonsecure" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          transferMode="Streamed">
          <security mode="None" />
        </binding>
      </webHttpBinding>
    </bindings>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

Tags
Grid
Asked by
Sumathi
Top achievements
Rank 1
Answers by
Jaya
Top achievements
Rank 1
Sumathi
Top achievements
Rank 1
Share this question
or