Hello,
I have master and detail table, both having custom paging option set to true and viewstate for page as well as grid is set to false.
The problems are -
1. If I expand row to see the details then it do not collaps. If I expand another row then the row expanded earlier row will collaps. The same row can not be collapsed once expanded.
2. I am binding sales order data using a stored proc. The stored proc extracts no of orders set as per the page size i.e if page size is 10 the proc returns only 10 orders from the table. If page size is 15 then only 15 orders are returned. So If I select page 2 and my page size is 15 then order no 16 to 30 would be extracted from the table and returned by the stored proc. This behaviour works great for main grid table where order header info is displayed. (I have more than 2000K orders in the order master.) But if I try to use the same technique for detail table it fails. E.g. - Order no 2 has 500 items into it. I want to display 50 items per page of detail table. The initial display is correct i.e the detail table displays 50 items on page 1 and shows count of 10 pages. Then if I click on the page 2 of detail table, rather than showing items from 51 to 100 entire grid (main grid) is rebound. So I am not able to jump on page 2 of any order detail.
Pls help...
Following is the code-
aspx -
<%@ Page Title="Sales Order" Language="C#" enableViewState="false" ViewStateMode="Disabled" MasterPageFile="~/Erp.Master" AutoEventWireup="true" CodeBehind="SalesOrderEntry.aspx.cs" Inherits="ErpWebApplication.TransactionData.SalesOrderEntry" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGridSalesOrder">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGridSalesOrder" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManagerProxy>
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
<%--<Services>
<asp:ServiceReference Path="~/Services/FetchData.svc" />
</Services>--%>
</asp:ScriptManagerProxy>
<br />
<div id="DivMessage" runat="server" >
<asp:Label ID="LblMessage" runat="server" Text=""></asp:Label>
</div>
<div class="clearfix"></div>
<%--<br />--%>
<fieldset class="border-inset">
<legend class="caption-for-selected-page-header"> Sales Order </legend>
<div id="DivDataDisplayInGrid" runat="server" class="col-md-16" style="background-color:transparent;">
<div id="DivButtonTop" class="col-md-16" runat="server">
<fieldset class="border-for-div text-align-Left">
<legend class="caption-for-div"> Action </legend>
<telerik:RadButton ID="btnAddTop" runat="server" Text="Add" RenderMode="Auto" ToolTip="Add SO" OnClick="btnAddTop_Click" CausesValidation="False">
<Icon PrimaryIconCssClass="rbAdd" PrimaryIconLeft="5" PrimaryIconTop="5"></Icon>
</telerik:RadButton>
<telerik:RadButton ID="btnEditTop" runat="server" Text="Edit" RenderMode="Auto" ToolTip="Edit SO" OnClick="btnEditTop_Click" CausesValidation="False" >
<Icon PrimaryIconCssClass="rbEdit" PrimaryIconLeft="5" PrimaryIconTop="5"></Icon>
</telerik:RadButton>
<telerik:RadButton ID="btnSaveTop" runat="server" Text="Save" RenderMode="Auto" ToolTip="Save/Update SO" OnClick="btnSaveTop_Click" OnClientClicking="SaveConfirm">
<Icon PrimaryIconCssClass="rbSave" PrimaryIconLeft="5" PrimaryIconTop="5"></Icon>
</telerik:RadButton>
<telerik:RadButton ID="btnAbortTop" runat="server" Text="Abort" RenderMode="Auto" ToolTip="Abort" OnClick="btnAbortTop_Click" OnClientClicking="SaveConfirm" CausesValidation="False">
<Icon PrimaryIconCssClass="rbCancel" PrimaryIconLeft="5" PrimaryIconTop="5"></Icon>
</telerik:RadButton>
<telerik:RadButton ID="btnRefreshTop" runat="server" Text="Refresh" RenderMode="Auto" ToolTip="Refresh" OnClick="btnRefreshTop_Click" CausesValidation="False">
<Icon PrimaryIconCssClass="rbRefresh" PrimaryIconLeft="5" PrimaryIconTop="5"></Icon>
</telerik:RadButton>
</fieldset>
</div>
<div class="clearfix"></div>
<br />
<div id="DivGrid" class="col-md-16" runat="server">
<fieldset class="border-for-div">
<legend class="caption-for-div"> Sales Order List </legend>
<%-- <telerik:RadSearchBox ID="SearchRegionName" EmptyMessage="Search Region" Width="100%" runat="server" DataContextKeyField="RegionName" TabIndex="1" OnSearch="SearchRegionName_Search" EnableAutoComplete="true" >
<WebServiceSettings Path="SalesOrder.aspx" Method="GetSearchBoxResults" />
</telerik:RadSearchBox>--%>
<telerik:RadGrid ID="RadGridSalesOrder" runat="server" EnableHeaderContextMenu="true" AllowFilteringByColumn="True" AutoPostBackOnFilter="true" EnableViewState="false"
AllowPaging="True" EnableLinqExpressions="false" AllowCustomPaging="true" AllowSorting="True" AutoGenerateColumns="False" RenderMode="Auto"
GroupPanelPosition="Top" ShowGroupPanel="false"
OnNeedDataSource="RadGridSalesOrder_NeedDataSource"
OnDetailTableDataBind="RadGridSalesOrder_DetailTableDataBind"
OnItemCommand="RadGridSalesOrder_ItemCommand"
OnPageIndexChanged="RadGridSalesOrder_PageIndexChanged"
OnSortCommand="RadGridSalesOrder_SortCommand"
OnPageSizeChanged="RadGridSalesOrder_PageSizeChanged" >
<ClientSettings AllowDragToGroup="True" EnableRowHoverStyle="True" >
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
<Selecting AllowRowSelect="True" />
<ClientEvents OnRowSelected="OnRowSelected" />
<%--<ClientEvents OnCommand="RadGrid1_Command"></ClientEvents>--%>
</ClientSettings>
<MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="SalesOrderId" AllowMultiColumnSorting="true" ClientDataKeyNames="SalesOrderId" Name="MasterTbl" EnableViewState="false" >
<CommandItemSettings ShowAddNewRecordButton="false" ShowCancelChangesButton="false" ShowExportToCsvButton ="false" ShowExportToExcelButton ="false" ShowExportToPdfButton ="false"
ShowExportToWordButton ="false" ShowSaveChangesButton ="false" />
<SortExpressions>
<telerik:GridSortExpression FieldName="SalesOrderId" SortOrder="Descending" />
</SortExpressions>
<DetailTables>
<telerik:GridTableView DataKeyNames="ItemCode" Name="OrderDetail" Width="100%" AllowCustomSorting="false" AllowCustomPaging="true" EnableViewState="false" AllowFilteringByColumn="false" PageSize="10" ShowFooter="true" AllowSorting="false" HierarchyLoadMode="ServerBind" HierarchyDefaultExpanded="true">
<SortExpressions>
<telerik:GridSortExpression FieldName="ItemCode" SortOrder="Ascending" />
</SortExpressions>
<Columns>
<telerik:GridBoundColumn HeaderText="Item Code" DataField="ItemCode" SortExpression="ItemCode" UniqueName="ItemCode" Groupable="False" AllowFiltering="false" Visible="True" FilterControlWidth="60%" >
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="10%" />
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="10%" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Item Name" DataField="ItemName" SortExpression="ItemName" UniqueName="ItemName" Groupable="False" AllowFiltering="false" Visible="True" FilterControlWidth="60%" FooterText ="Total : " >
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="30%" />
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="30%" />
<FooterStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="30%" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Qty" DataField="OrderQty" Aggregate="Sum" SortExpression="OrderQty" UniqueName="OrderQty" Groupable="False" AllowFiltering="false" Visible="True" FilterControlWidth="60%" DataFormatString="{0:###0.00}" >
<ItemStyle HorizontalAlign="Right" VerticalAlign="Top" Width="10%" />
<HeaderStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="10%" />
<FooterStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="10%" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Rate" DataField="Rate" SortExpression="Rate" UniqueName="Rate" Groupable="False" AllowFiltering="false" Visible="false" FilterControlWidth="60%" DataFormatString="{0:###0.00}">
<ItemStyle HorizontalAlign="Right" VerticalAlign="Top" Width="10%" />
<HeaderStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="10%" />
</telerik:GridBoundColumn>
<%--<telerik:GridBoundColumn HeaderText="Amount" DataField="Amount" SortExpression="Amount" UniqueName="Amount" Groupable="False" AllowFiltering="false" Visible="True" FilterControlWidth="60%" DataFormatString="{0:###0.00}">
<ItemStyle HorizontalAlign="Right" VerticalAlign="Top" Width="10%" />
<HeaderStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="10%" />
</telerik:GridBoundColumn>--%>
<telerik:GridCalculatedColumn HeaderText="Amount" UniqueName="Amount" DataType="System.Double" DataFields="OrderQty, Rate" Expression="{0}*{1}" FooterText="Total : " Aggregate="Sum" DataFormatString="{0:###0.00}">
<ItemStyle HorizontalAlign="Right" VerticalAlign="Top" Width="10%" />
<HeaderStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="10%" />
<FooterStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="10%" />
</telerik:GridCalculatedColumn>
<telerik:GridTemplateColumn HeaderText="Status" DataField ="IsActive" UniqueName="IsActive" Groupable="false" AllowSorting="false" AllowFiltering="false" Visible="true" >
<ItemTemplate>
<%# Boolean.Parse(Eval("IsActive").ToString()) ? "<font color='#006600'><b> Active</b></font>" : "<font color='#990000'><b>Inactive</b></font>" %>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="10%" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="10%" />
</telerik:GridTemplateColumn>
</Columns>
<PagerStyle Mode="NextPrevNumericAndAdvanced" />
</telerik:GridTableView>
</DetailTables>
<Columns>
<%-- <telerik:GridClientSelectColumn Text="Edit" UniqueName="colRowSelect" Visible="False">
</telerik:GridClientSelectColumn>
<telerik:GridEditCommandColumn UniqueName="edtColumn" ButtonType="ImageButton">
</telerik:GridEditCommandColumn>--%>
<telerik:GridBoundColumn HeaderText="SO Id" DataField="SalesOrderId" SortExpression="SalesOrderId" UniqueName="SalesOrderId" Groupable="False" AllowFiltering="True" Visible="True" FilterControlWidth="60%" >
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="10%" />
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="10%" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="SO Date" DataField="SalesOrderDate" SortExpression="SalesOrderDate" UniqueName="SalesOrderDate" Groupable="true" AllowFiltering="True" Visible="True" FilterControlWidth="60%" DataFormatString="{0:dd/MM/yyyy}" >
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="10%" />
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="10%" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Party Name" DataField="PartyName" SortExpression="PartyName" UniqueName="PartyName" Groupable="True" AllowFiltering="True" Visible="True" FilterControlWidth="90%">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="47%" />
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="47%" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Party Ref No" DataField="PartyRefPONo" SortExpression="PartyRefPONo" UniqueName="PartyRefPONo" Groupable="false" AllowFiltering="True" Visible="True" FilterControlWidth="70%">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="10%" />
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="10%" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Party Ref Date" DataField="PartyRefPODate" SortExpression="PartyRefPODate" UniqueName="PartyRefPODate" Groupable="false" AllowFiltering="True" Visible="True" FilterControlWidth="70%" DataFormatString="{0:dd/MM/yyyy}">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="10%" />
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="10%" />
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Status" DataField ="IsActive" UniqueName="IsActive" Groupable="false" AllowSorting="false" AllowFiltering="false" Visible="true" >
<ItemTemplate>
<%# Boolean.Parse(Eval("IsActive").ToString()) ? "<font color='#006600'><b> Active</b></font>" : "<font color='#990000'><b>Inactive</b></font>" %>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="10%" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="10%" />
</telerik:GridTemplateColumn>
<%--<telerik:GridButtonColumn CommandName="Delete" Text="Deactivate" UniqueName="column" ButtonType="ImageButton" ConfirmText="Are you Sure ?" ConfirmTitle="Confirm" ShowSortIcon="False">
</telerik:GridButtonColumn>--%>
</Columns>
<CommandItemStyle HorizontalAlign="Left" />
</MasterTableView>
<PagerStyle Mode="NextPrevNumericAndAdvanced" />
<FilterMenu CssClass="cssForFilterButton">
</FilterMenu>
<CommandItemStyle HorizontalAlign="Left" />
<FilterItemStyle HorizontalAlign="Left" />
<GroupingSettings ShowUnGroupButton = "false" />
</telerik:RadGrid>
</fieldset>
</div>
<div class="clearfix"></div>
<div id="DivDataForm" class="col-md-16" style="background-color:transparent;" runat="server">
<div id="DivRegionName" class="col-md-16">
<fieldset class="border-for-div">
<legend class="caption-for-div">Sales Order</legend>
<asp:HiddenField ID="hdnSalesOrderId" runat="server" Value="0" />
<asp:HiddenField ID="hdnVisibleDiv" runat="server" Value="DivGrid" />
<label class="MTIPLRadTextBoxLabel label-font-setting-small left-padding-5">Region Name :</label>
<asp:TextBox ID="TxtRegionName" runat="server" Width="100%" TabIndex="2" CausesValidation="True" placeholder="Enter Region Name">
</asp:TextBox>
<asp:RequiredFieldValidator ID="ReqRegion" runat="server" ErrorMessage="Region Name can not be blank" ControlToValidate="TxtRegionName" Display="Dynamic" CssClass="ruError" EnableClientScript="true"></asp:RequiredFieldValidator>
</fieldset>
</div>
<div class="clearfix"></div>
<br />
<div class="col-md-16">
<fieldset class="border-for-div">
<legend class="caption-for-div">Status</legend>
<asp:Radiobutton ID="RbActive" runat="server" Text="Active" Checked="true" TabIndex="31" class="label-font-setting-medium" GroupName="ActiveInactive" />
<asp:Radiobutton ID="RbInactive" runat="server" Text="In-Active" TabIndex="32" class="label-font-setting-medium" GroupName="ActiveInactive" />
<%--<asp:Button ID="Button1" runat="server" Text="Save" style="visibility:hidden;"/>--%>
</fieldset>
</div>
</div>
<div class="clearfix"></div>
<br />
<div class="col-md-16">
<fieldset class="border-for-div text-align-Left">
<legend class="caption-for-div"> Action </legend>
<telerik:RadButton ID="btnAddBottom" runat="server" Text="Add" RenderMode="Lightweight" ToolTip="Add SO" OnClick="btnAddTop_Click" CausesValidation="False">
<Icon PrimaryIconCssClass="rbAdd" PrimaryIconLeft="5" PrimaryIconTop="5"></Icon>
</telerik:RadButton>
<telerik:RadButton ID="btnEditBottom" runat="server" Text="Edit" RenderMode="Lightweight" ToolTip="Edit SO" OnClick="btnEditTop_Click" CausesValidation="False">
<Icon PrimaryIconCssClass="rbEdit" PrimaryIconLeft="5" PrimaryIconTop="5"></Icon>
</telerik:RadButton>
<telerik:RadButton ID="btnSaveBottom" runat="server" Text="Save" RenderMode="Lightweight" ToolTip="Save/Update SO" OnClick="btnSaveTop_Click" OnClientClicking="SaveConfirm">
<Icon PrimaryIconCssClass="rbSave" PrimaryIconLeft="5" PrimaryIconTop="5"></Icon>
</telerik:RadButton>
<telerik:RadButton ID="btnAbortBottom" runat="server" Text="Abort" RenderMode="Auto" ToolTip="Abort" OnClick="btnAbortTop_Click" OnClientClicking="SaveConfirm" CausesValidation="False">
<Icon PrimaryIconCssClass="rbCancel" PrimaryIconLeft="5" PrimaryIconTop="5"></Icon>
</telerik:RadButton>
<telerik:RadButton ID="btnRefreshBottom" runat="server" Text="Refresh" RenderMode="Auto" ToolTip="Refresh" OnClick="btnRefreshTop_Click" CausesValidation="False">
<Icon PrimaryIconCssClass="rbRefresh" PrimaryIconLeft="5" PrimaryIconTop="5"></Icon>
</telerik:RadButton>
</fieldset>
</div>
<div class="clearfix"></div>
<br />
</div>
</fieldset>
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript">
function SaveConfirm(sender, args) {
args.set_cancel(!window.confirm("Are you sure ?"));
}
function OnRowSelected(sender, args) {
var SoId = args.getDataKeyValue("SalesOrderId");
var hdnControl = document.getElementById('<%= hdnSalesOrderId.ClientID%>');
hdnControl.value = SoId;
//alert(hdnControl.value);
}
</script>
</telerik:RadScriptBlock>
</asp:Content>
C# -
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using MTIPLSQLCommonClass;
using ModelClasses;
using ErpBusinessDataLayer;
using System.Globalization;
namespace ErpWebApplication.TransactionData
{
public partial class SalesOrderEntry : System.Web.UI.Page
{
#region library class instances
clsSQLCommonLib objFunLib = new clsSQLCommonLib();
clsRegionMasterBDL objRegionMaster = new clsRegionMasterBDL();
#endregion
#region Variable declaration
int intVirtualRowCount = 0, intVirtualRowCount1 = 0, intVirtualRowCount2 = 0, intDtlTblCurrentPageIndex = 0;
const int ItemsPerRequest = 10;
#endregion
#region static variables for radgrid
string strSalesOrderId;
static string strSortOrder = null;
static string strRadGridFilter = null;
static int intPageIndex = 1;
static List<ClsFilterCriteria> objClsFilterCriteria = new List<ClsFilterCriteria>();
#endregion
protected void Page_Load(object sender, EventArgs e)
{
this.Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "Global", this.ResolveClientUrl("~/Include/javaFunctionLib.js"));
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
DateTimeFormatInfo dtf = new System.Globalization.DateTimeFormatInfo();
dtf.ShortDatePattern = "dd/MM/yyyy";
ci.DateTimeFormat = dtf;
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoServerCaching();
HttpContext.Current.Response.Cache.SetNoStore();
Response.AddHeader("Refresh", Convert.ToString((Session.Timeout * 60) + 10) + "; url=" + ResolveServerUrl("~/login/frmLogin.aspx"));
RadInputManager mpRadInputManager;
mpRadInputManager = (RadInputManager)Master.FindControl("RadInputManager1");
if (mpRadInputManager != null)
{
DateInputSetting dateTextBoxSetting = (DateInputSetting)mpRadInputManager.GetSettingByBehaviorID("BIDateInput");
//dateTextBoxSetting.TargetControls.Add(new TargetInput(TxtOrderDate.UniqueID, true));
TextBoxSetting txtBoxSetting = (TextBoxSetting)mpRadInputManager.GetSettingByBehaviorID("BINotEmpty");
//txtBoxSetting.TargetControls.Add(new TargetInput(TxtVyasaRefNo.UniqueID, true));
//txtBoxSetting.TargetControls.Add(new TargetInput(TxtCustomerOrderNo.UniqueID, true));
}
if (!IsPostBack)
{
strSortOrder = null;
strRadGridFilter = null;
intPageIndex = 1;
objClsFilterCriteria = new List<ClsFilterCriteria>();
DivDataForm.Attributes["style"] = "Display:None;";
DivDataDisplayInGrid.Attributes["style"] = "Display:Normal;";
btnAddTop.Enabled = true;
btnAddBottom.Enabled = true;
btnEditTop.Enabled = true;
btnEditBottom.Enabled = true;
btnSaveTop.Enabled = false;
btnSaveBottom.Enabled = false;
btnAbortTop.Enabled = false;
btnAbortBottom.Enabled = false;
btnRefreshTop.Enabled = true;
btnRefreshBottom.Enabled = true;
ClsFilterCriteria TempClsFilter;
TempClsFilter = new ClsFilterCriteria();
TempClsFilter.ColumnName = "SalesOrderId";
TempClsFilter.FilterCriteria = null;
objClsFilterCriteria.Add(TempClsFilter);
TempClsFilter = new ClsFilterCriteria();
TempClsFilter.ColumnName = "SalesOrderDate";
TempClsFilter.FilterCriteria = null;
objClsFilterCriteria.Add(TempClsFilter);
TempClsFilter = new ClsFilterCriteria();
foreach (GridSortExpression exp in RadGridSalesOrder.MasterTableView.SortExpressions)
{
if (strSortOrder == "" | String.IsNullOrEmpty(strSortOrder))
{
strSortOrder = exp.ToString();
}
else
{
strSortOrder = strSortOrder + ", " + exp.ToString();
}
}
//RadGridSalesOrder.Rebind();
}
else
{
if (hdnVisibleDiv.Value == "DivDataForm")
{
DivDataForm.Attributes["style"] = "Display:Normal;";
DivGrid.Attributes["style"] = "Display:None;";
btnRefreshTop.Enabled = false;
btnRefreshBottom.Enabled = false;
}
else
{
DivDataForm.Attributes["style"] = "Display:None;";
DivGrid.Attributes["style"] = "Display:Normal;";
btnRefreshTop.Enabled = true;
btnRefreshBottom.Enabled = true;
}
}
}
public static string ResolveServerUrl(string serverUrl, bool forceHttps)
{
// *** Is it already an absolute Url?
if (serverUrl.IndexOf("://") > -1)
return serverUrl;
// *** Start by fixing up the Url an Application relative Url
string newUrl = System.Web.VirtualPathUtility.ToAbsolute(serverUrl); //ResolveServerUrl(serverUrl);
Uri originalUri = HttpContext.Current.Request.Url;
newUrl = (forceHttps ? "https" : originalUri.Scheme) +
"://" + originalUri.Authority + newUrl;
return newUrl;
}
public static string ResolveServerUrl(string serverUrl)
{
return ResolveServerUrl(serverUrl, false);
}
#region button events
//Same event is used for save buttom based at bottom
protected void btnSaveTop_Click(object sender, EventArgs e) //Same event is used for save buttom based at bottom
{
if (!Page.IsValid)
{
DivMessage.Attributes["class"] = "error rounded-corners";
LblMessage.Text = "Data validation failed";
ClientScript.RegisterStartupScript(this.GetType(), "HideLabel", "<script type=\"text/javascript\">setTimeout(\"document.getElementById('" + DivMessage.ClientID + "').style.display='none'\",20000)</script>");
DivDataForm.Attributes["style"] = "Display:Normal;";
DivGrid.Attributes["style"] = "Display:None;";
btnAddTop.Enabled = false;
btnAddBottom.Enabled = false;
btnEditTop.Enabled = false;
btnEditBottom.Enabled = false;
btnSaveTop.Enabled = true;
btnSaveBottom.Enabled = true;
btnAbortTop.Enabled = true;
btnAbortBottom.Enabled = true;
hdnVisibleDiv.Value = "DivDataForm";
btnRefreshTop.Enabled = false;
btnRefreshBottom.Enabled = false;
return;
}
else
{
objRegionMaster.RegionId = Convert.ToInt16(hdnSalesOrderId.Value);
objRegionMaster.RefCompanyId = Convert.ToByte(Request.Cookies["RefCompanyId"].Value);
objRegionMaster.RegionName = TxtRegionName.Text;
objRegionMaster.IsActive = RbActive.Checked == true ? true : false;
objRegionMaster.SaveData();
DivMessage.Attributes["style"] = "Display:Normal;";
if (objRegionMaster.IntMessageCode == 1 | objRegionMaster.IntMessageCode == 2)
{
DivMessage.Attributes["class"] = "success rounded-corners";
}
else
{
DivMessage.Attributes["class"] = "error rounded-corners";
}
LblMessage.Text = objRegionMaster.StrMessage;
ClientScript.RegisterStartupScript(this.GetType(), "HideLabel", "<script type=\"text/javascript\">setTimeout(\"document.getElementById('" + DivMessage.ClientID + "').style.display='none'\",20000)</script>");
DivDataForm.Attributes["style"] = "Display:None;";
DivGrid.Attributes["style"] = "Display:Normal;";
btnAddTop.Enabled = true;
btnAddBottom.Enabled = true;
btnEditTop.Enabled = true;
btnEditBottom.Enabled = true;
btnSaveTop.Enabled = false;
btnSaveBottom.Enabled = false;
btnAbortTop.Enabled = false;
btnAbortBottom.Enabled = false;
hdnVisibleDiv.Value = "DivGrid";
btnRefreshTop.Enabled = true;
btnRefreshBottom.Enabled = true;
RadGridSalesOrder.DataSource = null;
RadGridSalesOrder.Rebind();
}
// btnAddTop_Click(sender, e);
}
//Same event is used for Add buttom based at bottom
protected void btnAddTop_Click(object sender, EventArgs e)
{
DivDataForm.Attributes["style"] = "Display:Normal;";
DivGrid.Attributes["style"] = "Display:None;";
btnAddTop.Enabled = false;
btnAddBottom.Enabled = false;
btnEditTop.Enabled = false;
btnEditBottom.Enabled = false;
btnSaveTop.Enabled = true;
btnSaveBottom.Enabled = true;
btnAbortTop.Enabled = true;
btnAbortBottom.Enabled = true;
hdnVisibleDiv.Value = "DivDataForm";
btnRefreshTop.Enabled = false;
btnRefreshBottom.Enabled = false;
hdnSalesOrderId.Value = "0";
TxtRegionName.Text = String.Empty;
}
//Same event is used for edit buttom based at bottom
protected void btnEditTop_Click(object sender, EventArgs e)
{
DivDataForm.Attributes["style"] = "Display:Normal;";
DivGrid.Attributes["style"] = "Display:None;";
btnAddTop.Enabled = false;
btnAddBottom.Enabled = false;
btnEditTop.Enabled = false;
btnEditBottom.Enabled = false;
btnSaveTop.Enabled = true;
btnSaveBottom.Enabled = true;
btnAbortTop.Enabled = true;
btnAbortBottom.Enabled = true;
hdnVisibleDiv.Value = "DivDataForm";
btnRefreshTop.Enabled = false;
btnRefreshBottom.Enabled = false;
objRegionMaster.GetData(hdnSalesOrderId.Value);
TxtRegionName.Text = objRegionMaster.RegionName.ToString();
if (objRegionMaster.IsActive == true)
{
RbActive.Checked = true;
RbInactive.Checked = false;
}
else
{
RbActive.Checked = false;
RbInactive.Checked = true;
}
}
//Same event is used for abort buttom based at bottom
protected void btnAbortTop_Click(object sender, EventArgs e)
{
DivDataForm.Attributes["style"] = "Display:None;";
DivGrid.Attributes["style"] = "Display:Normal;";
btnAddTop.Enabled = true;
btnAddBottom.Enabled = true;
btnEditTop.Enabled = true;
btnEditBottom.Enabled = true;
btnSaveTop.Enabled = false;
btnSaveBottom.Enabled = false;
btnAbortTop.Enabled = false;
btnAbortBottom.Enabled = false;
hdnVisibleDiv.Value = "DivGrid";
btnRefreshTop.Enabled = true;
btnRefreshBottom.Enabled = true;
}
//Same event is used for abort buttom based at bottom
protected void btnRefreshTop_Click(object sender, EventArgs e)
{
RadGridSalesOrder.Rebind();
btnAddTop.Enabled = true;
btnAddBottom.Enabled = true;
btnEditTop.Enabled = true;
btnEditBottom.Enabled = true;
btnSaveTop.Enabled = false;
btnSaveBottom.Enabled = false;
btnAbortTop.Enabled = false;
btnAbortBottom.Enabled = false;
btnRefreshTop.Enabled = true;
btnRefreshBottom.Enabled = true;
}
#endregion
#region validation rules
protected void ValidateForNotBlank(object source, ServerValidateEventArgs e)
{
if (e.Value.Length == 0)
e.IsValid = false;
else
e.IsValid = true;
}
#endregion
#region radgrid events
protected void RadGridSalesOrder_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
if (!e.IsFromDetailTable)
{
RadGridSalesOrder.DataSource = objFunLib.GetDataTableForRadgridCustomPaging("SalesOrderMaster INNER JOIN PartyMaster ON SalesOrderMaster.PartyId = PartyMaster.PartyId", intPageIndex, RadGridSalesOrder.PageSize, "SalesOrderMaster.SalesOrderId, SalesOrderMaster.SalesOrderDate, PartyMaster.PartyName, SalesOrderMaster.PartyRefPONo, SalesOrderMaster.PartyRefPODate, SalesOrderMaster.IsActive", strSortOrder, strRadGridFilter, ref intVirtualRowCount);
RadGridSalesOrder.MasterTableView.VirtualItemCount = intVirtualRowCount;
}
}
protected void RadGridSalesOrder_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
{
GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
switch (e.DetailTableView.Name)
{
case "OrderDetail":
{
int intPageIndex = e.DetailTableView.CurrentPageIndex+1;
strSalesOrderId = dataItem.GetDataKeyValue("SalesOrderId").ToString();
e.DetailTableView.DataSource = objFunLib.GetDataTableForRadgridCustomPaging("SalesOrderDetail INNER JOIN ItemMaster ON SalesOrderDetail.ItemCode = ItemMaster.ItemCode", 1, RadGridSalesOrder.PageSize, "SalesOrderDetail.ItemCode, ItemMaster.ItemName, SalesOrderDetail.OrderQty, SalesOrderDetail.Rate, SalesOrderDetail.IsActive", strSortOrder, " SalesOrderDetail.SalesOrderId = '" + strSalesOrderId + "'", ref intVirtualRowCount1);
e.DetailTableView.VirtualItemCount = intVirtualRowCount1;
e.DetailTableView.CurrentPageIndex = intPageIndex - 1;
break;
}
case "Order":
{
//string OrderID = dataItem.GetDataKeyValue("OrderID").ToString();
//e.DetailTableView.DataSource = GetDataTable("SELECT * FROM [Order Details] WHERE OrderID = " + OrderID);
break;
}
}
}
protected void RadGridSalesOrder_PageIndexChanged(object sender, GridPageChangedEventArgs e)
{
intPageIndex = e.NewPageIndex + 1;
RadGridSalesOrder.DataSource = null;
RadGridSalesOrder.Rebind();
}
protected void RadGridSalesOrder_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
{
intPageIndex = 1;
}
protected void RadGridSalesOrder_ItemCommand(object sender, GridCommandEventArgs e)
{
string strFilter = "";
if ((e.CommandName == RadGrid.FilterCommandName))
{
DataTable objDt;
Pair filterPair = (Pair)e.CommandArgument;
e.Canceled = true;
foreach (ClsFilterCriteria obb in objClsFilterCriteria)
{
if (obb.ColumnName.ToUpper() == filterPair.Second.ToString().ToUpper())
{
TextBox filterBox = (e.Item as GridFilteringItem)[filterPair.Second.ToString()].Controls[0] as TextBox;
obb.FilterCriteria = objFunLib.GetFilterCriteria(filterPair.First.ToString(), filterBox.Text) == "" ? null : objFunLib.GetFilterCriteria(filterPair.First.ToString(), filterBox.Text);
if (obb.FilterCriteria == null)
{
foreach (GridColumn column in RadGridSalesOrder.MasterTableView.RenderColumns)
{
if (column.SupportsFiltering())
{
if (filterPair.Second.ToString().ToUpper() == column.UniqueName.ToString().ToUpper())
{
column.CurrentFilterValue = string.Empty;
}
}
}
}
}
}
foreach (ClsFilterCriteria obb in objClsFilterCriteria)
{
if (obb.FilterCriteria != null & obb.FilterCriteria != "")
{
if (strFilter == "")
{
strFilter = obb.ColumnName + " " + obb.FilterCriteria;
}
else
{
strFilter = strFilter + " And " + obb.ColumnName + " " + obb.FilterCriteria + " ";
}
}
}
strRadGridFilter = strFilter;
intPageIndex = 1;
//RadGridSalesOrder.DataSource = objFunLib.GetDataTableForRadgridCustomPaging("RegionMaster", intPageIndex, RadGridSalesOrder.PageSize, "RegionId, RegionName, IsActive", strSortOrder, strRadGridFilter, ref intVirtualRowCount);
RadGridSalesOrder.DataSource = objFunLib.GetDataTableForRadgridCustomPaging("SalesOrderMaster INNER JOIN PartyMaster ON SalesOrderMaster.PartyId = PartyMaster.PartyId", intPageIndex, RadGridSalesOrder.PageSize, "SalesOrderMaster.SalesOrderId, SalesOrderMaster.SalesOrderDate, PartyMaster.PartyName, SalesOrderMaster.PartyRefPONo, SalesOrderMaster.PartyRefPODate, SalesOrderMaster.IsActive", strSortOrder, strRadGridFilter, ref intVirtualRowCount);
RadGridSalesOrder.MasterTableView.VirtualItemCount = intVirtualRowCount;
RadGridSalesOrder.Rebind();
}
DivDataForm.Attributes["style"] = "Display:None;";
DivGrid.Attributes["style"] = "Display:Normal;";
btnAddTop.Enabled = true;
btnAddBottom.Enabled = true;
btnEditTop.Enabled = true;
btnEditBottom.Enabled = true;
btnSaveTop.Enabled = false;
btnSaveBottom.Enabled = false;
btnAbortTop.Enabled = false;
btnAbortBottom.Enabled = false;
hdnVisibleDiv.Value = "DivGrid";
btnRefreshTop.Enabled = true;
btnRefreshBottom.Enabled = true;
}
protected void RadGridSalesOrder_SortCommand(object sender, GridSortCommandEventArgs e)
{
int intLoc = 0;
GridTableView tableView = e.Item.OwnerTableView;
e.Canceled = true;
GridSortExpression expression = new GridSortExpression();
if (expression.SortOrder != GridSortOrder.None)
{
expression.FieldName = e.SortExpression;
if (RadGridSalesOrder.MasterTableView.SortExpressions.ContainsExpression(e.SortExpression))
{
intLoc = RadGridSalesOrder.MasterTableView.SortExpressions.IndexOf(expression) < 0 ? 0 : RadGridSalesOrder.MasterTableView.SortExpressions.IndexOf(expression);
}
if (RadGridSalesOrder.MasterTableView.SortExpressions.Count == 0 || RadGridSalesOrder.MasterTableView.SortExpressions[intLoc].FieldName != e.SortExpression)
{
expression.SortOrder = GridSortOrder.Descending;
}
else if (RadGridSalesOrder.MasterTableView.SortExpressions[intLoc].SortOrder == GridSortOrder.Descending)
{
expression.SortOrder = GridSortOrder.Ascending;
}
else if (RadGridSalesOrder.MasterTableView.SortExpressions[intLoc].SortOrder == GridSortOrder.Ascending)
{
expression.SortOrder = GridSortOrder.None;
}
else if (RadGridSalesOrder.MasterTableView.SortExpressions[intLoc].SortOrder == GridSortOrder.None)
{
expression.SortOrder = GridSortOrder.Descending;
}
if (string.IsNullOrEmpty(strSortOrder) == false)
{
strSortOrder = strSortOrder.Replace(e.SortExpression + " " + "ASC,", "");
strSortOrder = strSortOrder.Replace(e.SortExpression + " " + "DESC,", "");
strSortOrder = strSortOrder.Replace(e.SortExpression + " " + "ASC", "");
strSortOrder = strSortOrder.Replace(e.SortExpression + " " + "DESC", "");
strSortOrder = strSortOrder.Replace(e.SortExpression + ", ", "");
strSortOrder = strSortOrder.Replace(e.SortExpression + " ", "");
strSortOrder = strSortOrder.Replace(e.SortExpression, "");
strSortOrder = strSortOrder.Trim();
}
if (strSortOrder == "" | String.IsNullOrEmpty(strSortOrder))
{
if (expression.SortOrder == GridSortOrder.None)
{
strSortOrder = expression.ToString() + "ASC";
}
else
{
strSortOrder = expression.ToString();
}
}
else
{
if (strSortOrder.Substring(0, 1) == ",")
{
strSortOrder = strSortOrder.Substring(1, strSortOrder.Trim().Length - 1);
}
if (strSortOrder.Substring(strSortOrder.Trim().Length - 1, 1) == ",")
{
strSortOrder = strSortOrder.Substring(0, strSortOrder.Trim().Length - 1);
}
if (expression.SortOrder != GridSortOrder.None)
{
strSortOrder = strSortOrder + ", " + expression.ToString();
}
}
RadGridSalesOrder.MasterTableView.SortExpressions.AddSortExpression(expression);
DivDataForm.Attributes["style"] = "Display:None;";
DivGrid.Attributes["style"] = "Display:Normal;";
btnAddTop.Enabled = true;
btnAddBottom.Enabled = true;
btnEditTop.Enabled = true;
btnEditBottom.Enabled = true;
btnSaveTop.Enabled = false;
btnSaveBottom.Enabled = false;
btnAbortTop.Enabled = false;
btnAbortBottom.Enabled = false;
hdnVisibleDiv.Value = "DivGrid";
btnRefreshTop.Enabled = true;
btnRefreshBottom.Enabled = true;
RadGridSalesOrder.DataSource = null;
RadGridSalesOrder.Rebind();
}
}
#endregion
}
}
Thanks
Milind