Chancing ASPxGridView data - asp.net

I would like to change my gridview data. My data type are integer, but I want to divide this data with 100 For example;
They must be;
200,00
100,00
50,00
I tried do this with OnCustomColumnDisplayText event but when I added this event it was working more than one. When open the page, many times was worked again and again. So many times I divided with 100. Can you help me, please? My codes below;
<dx:ASPxGridView ID="MainDataList" ClientInstanceName="mainDataDl" runat="server" CssClass="mainDataList"
AutoGenerateColumns="False" EnableRowsCache="false" OnDataBinding="MainDataList_DataBinding" Width="100%"
OnRowUpdating="MainDataList_RowUpdating" OnCustomColumnDisplayText="MainDataList_CustomColumnDisplayText" >
<ClientSideEvents Init="grid_Init" />
<SettingsAdaptivity AdaptivityMode="HideDataCells" HideDataCellsAtWindowInnerWidth="600"
AllowOnlyOneAdaptiveDetailExpanded="true" AllowHideDataCellsByColumnMinWidth="true" />
<EditFormLayoutProperties>
<SettingsAdaptivity AdaptivityMode="SingleColumnWindowLimit" SwitchToSingleColumnAtWindowInnerWidth="680" />
</EditFormLayoutProperties>
<SettingsEditing Mode="EditFormAndDisplayRow" EditFormColumnCount="2"/>
<Styles>
<Header ForeColor="White" BackColor="#969696" Font-Size="12px" />
<Cell Font-Size="12px" Wrap="False" />
<EditForm CssClass="editForm" />
</Styles>
<Settings ShowFilterRow="True" AutoFilterCondition="Contains" />
<Columns>
<dx:GridViewCommandColumn ShowClearFilterButton="True" VisibleIndex="0" Name="TempColumn" >
</dx:GridViewCommandColumn>
</Columns>
<SettingsPager PageSize="10" NumericButtonCount="4" Mode="ShowPager" />
<TotalSummary />
<SettingsDataSecurity AllowDelete="False" AllowEdit="True" AllowInsert="False" />
<SettingsSearchPanel Visible="false" CustomEditorID="MainDataListSearchTextBox" />
<SettingsLoadingPanel Mode="Disabled" />
<SettingsBehavior AllowFocusedRow="True" ProcessFocusedRowChangedOnServer="true" />
<SettingsCommandButton>
<ShowAdaptiveDetailButton ButtonType="Image">
</ShowAdaptiveDetailButton>
<HideAdaptiveDetailButton ButtonType="Image">
</HideAdaptiveDetailButton>
</SettingsCommandButton>
</dx:ASPxGridView>
protected void MainDataList_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e)
{
foreach (MimasPortal.TableFieldData_1_0 tf in userSession.DetailStruct.Fields)
{
if (tf.FieldType == "MONEY")
{
DataRowView rowData = (DataRowView)MainDataList.GetRow(e.VisibleIndex);
if (rowData != null)
{
if (rowData.Row[tf.FieldName].ToString().Length > 2 && rowData.Row[tf.FieldName].ToString().IndexOf('.') < 1 && rowData.Row[tf.FieldName].ToString().IndexOf(',') < 1)
{
decimal newValue = (Convert.ToDecimal(e.GetFieldValue(tf.FieldName))) / 100;
rowData.Row[tf.FieldName] = newValue;
}
else
{
rowData.Row[tf.FieldName] = e.GetFieldValue(tf.FieldName).ToString();
}
}
}
}
}

Related

ASP.NET DropDown list selected value ERROR 'ddldept' has a SelectedValue which is invalid because it does not exist in the list of items

I am getting this error while clicking the edit button on my asp.net gridview.
'ddldept' has a SelectedValue which is invalid because it does not exist in the list of items.
This is my dropdown's SelectedIndexChanged event
protected void dgbus_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = dgbus.SelectedRow;
//here am getting the error
ddldept.SelectedValue = row.Cells[2].Text.ToString().Trim();
txtappcode1.Text = row.Cells[3].Text.ToString();
txtappcode2.Text = row.Cells[4].Text.ToString();
hdn.Value = row.Cells[1].Text.ToString();
lblMsg.Text = "";
}
eveything is working fine, but when I try to edit a row having row.Cells[2].Text as 'Finance & Accounts'..
Is this '&' a problem?
My Gridview markup
<asp:GridView ID="dgbus" runat="server" class="table-format"
AutoGenerateColumns="False" Width="100%"
OnSelectedIndexChanged="dgbus_SelectedIndexChanged"
OnRowCreated = "dgbus_RowCreated"
OnPageIndexChanging = "dgbus_PageIndexChanging" AllowPaging="True"
PageSize="50">
<Columns>
<asp:CommandField ButtonType="Image" HeaderText="Edit Details"
SelectImageUrl="~/images/modify.gif"
SelectText="Modify Approver"
ShowSelectButton="True" />
<asp:BoundField HeaderText="Approver ID" DataField="appid"/>
<asp:BoundField HeaderText="Deptt" DataField="deptt" />
<asp:BoundField HeaderText="Appcode1" DataField="appcode1" />
<asp:BoundField HeaderText="Appcode1" DataField="appcode2" />
</Columns>
<RowStyle CssClass="misctext" Height="20px" />
<HeaderStyle BackColor="ControlLight" CssClass="contentbold"
Height="20px" />
<PagerSettings PageButtonCount="5" />
<PagerStyle BackColor="Gainsboro" CssClass="link" HorizontalAlign="Right"
VerticalAlign="Middle" />
</asp:GridView>
Attempt to find the value in the drop down list before attempting to set the SelectedValue, like this:
if (ddldept.Items.FindByValue(row.Cells[2].Text.ToString().Trim()) != null)
{
ddldept.SelectedValue = row.Cells[2].Text.ToString().Trim();
}
So your full code should be this:
protected void dgbus_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = dgbus.SelectedRow;
if (ddldept.Items.FindByValue(row.Cells[2].Text.ToString().Trim()) != null)
{
ddldept.SelectedValue = row.Cells[2].Text.ToString().Trim();
}
txtappcode1.Text = row.Cells[3].Text.ToString();
txtappcode2.Text = row.Cells[4].Text.ToString();
hdn.Value = row.Cells[1].Text.ToString();
lblMsg.Text = "";
}

ASP.NET - GridView, adding header row in code

I've scoured the web looking at the various examples and have tried every single one of them. I get the same error no matter what. I am trying to add the headerrow to the GridView control in code. I have tried adding the below code in every possible event from gridview prerender to all of the events of the page. Same deal. Always get the error: The table must contain row sections in order of header, body, then footer.
I have stripped down the page to the bare essentials - removing the master page and all CSS.
Here is the aspx and grid view code:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Shipping.Admin.Default" Title="Apps - Shipping" %>
<html>
<head><title></title></head>
<body>
<form runat="server" id="form1">
<br />
<h1>Admin Page</h1>
<br />
<asp:GridView ID="gvShipments" runat="server" AllowSorting="True"
AutoGenerateColumns="False" onsorting="gvShipments_Sorting" Width="100%"
AllowPaging="True" onpageindexchanging="gvShipments_PageIndexChanging"
PageSize="50">
<PagerSettings Position="TopAndBottom" />
<Columns>
<asp:BoundField DataField="RequestDate" HeaderText="Request Date" SortExpression="dtRequestDate" />
<asp:BoundField DataField="Requestor" HeaderText="Requestor" SortExpression="Requestor" />
<asp:BoundField DataField="CompanyName" HeaderText="Company" SortExpression="CompanyName" />
<asp:BoundField DataField="ShipmentDescription" HeaderText="Description" SortExpression="ShipmentDescription" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:BoundField DataField="ShipmentType" HeaderText="Shipment Type" SortExpression="ShipmentType" />
<asp:BoundField DataField="ServiceLevel" HeaderText="Service Level" SortExpression="ServiceLevel" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
<asp:HyperLinkField DataNavigateUrlFields="ShipmentId" DataNavigateUrlFormatString="Shipment.aspx?CatId=Admin&sID={0}" Text=" edit" />
</Columns>
</asp:GridView>
<br />
</form>
</body>
</html>
Here is a snipped of the code-behind. This method is called in the Page_Load method:
private void LoadGridView()
{
DataSet ds = new DataSet();
ds = GetDataset();
DataTable dtRequests = ds.Tables["Admin"];
DataView dv = new DataView(dtRequests);
if (ViewState["sortexpression"] != null)
{
dv.Sort = ViewState["sortexpression"].ToString() + " " + ViewState["sortdirection"].ToString();
}
else
{
dv.Sort = "dtRequestDate DESC";
}
gvShipments.DataSource = dv;
gvShipments.DataBind();
**if (gvShipments.Rows.Count > 0)
{
this.gvShipments.UseAccessibleHeader = true;
this.gvShipments.HeaderRow.TableSection = TableRowSection.TableHeader;
}**
ds.Dispose();
}
I have tried adding the code inside bolded the IF statement everywhere. I am stumped. Please help!
Thanks
Try this add Page_PreRender event and post your code inside it, then your code look like as below
protected void Page_PreRender(object sender, EventArgs e)
{
if (gvShipments.Rows.Count > 0)
{
gvShipments.UseAccessibleHeader = true;
gvShipments.HeaderRow.TableSection = TableRowSection.TableHeader;
}
}
PageLifeCycle

ext.net.row editing ,how to triger update event fire ( OnBeforeRecordUpdated)

I have a srote like this
<ext:Store ID="strPos" runat="server" AutoSync="false" OnReadData="StoreChange_Event"
OnBeforeRecordUpdated="StorePostGuncelle" OnBeforeRecordInserted="StorePostEkle"
AutomaticResponseValues="false" OnBeforeRecordDeleted="StorePosSil">
I can ınserting values like that way,
grid.store.insert(0, r);
#{strPos}.sync();
grid.store.reload();
but the problem is when updating the value .when clcik the row ,open row editor,then I clcik the update button but no event fire .(I wanna fireOnBeforeRecordUpdaten event ).
I have already tried this ,
<Plugins>
<ext:RowEditing ID="RowEditing1" runat="server" CancelBtnText="İptal" SaveBtnText="Kaydet" ClicksToEdit="1" TriggerEvent="#{strPos}.sync();#{strPos}.reload();" >
</ext:RowEditing>
</Plugins>
and this one
<Plugins>
<ext:RowEditing ID="RowEditing1" runat="server" CancelBtnText="İptal" SaveBtnText="Kaydet" ClicksToEdit="1" SaveHandler="#{strPos}.sync();#{strPos}.reload();" SaveHandler="" >
</ext:RowEditing>
</Plugins>
but change nothing.
thank you
**
it is availbale this.up('gridpanel').store.removeAt(recordIndex); and insert method but where is the update method.
EDITED: complete example ;
<ext:XScript ID="XScript1" runat="server">
<script>
function addPlant(btn) {
// Create a model instance
var grid = #{GridPanel1};
grid.editingPlugin.cancelEdit();
var r = Ext.ModelManager.create({
Adi: 'pos bilgisi',
Id:'0'
} ,'Pos');
grid.store.insert(0, r);
#{strPos}.sync();
grid.store.reload();
// grid.editingPlugin.startEditByPosition({ row: 0, column: 1 });
}
</script>
</ext:XScript>
<ext:GridPanel ID="GridPanel1" Scroll="Vertical" runat="server" Title="Pos tanımlamalrı"
Height="200">
<Store>
<ext:Store ID="strPos" runat="server" AutoSync="false" OnReadData="StoreChange_Event" OnAfterStoreChanged="store_change"
OnBeforeRecordUpdated="StorePostGuncelle" OnBeforeRecordInserted="StorePostEkle"
AutomaticResponseValues="false" OnBeforeRecordDeleted="StorePosSil">
<Model>
<ext:Model ID="Model1" runat="server" Name="Pos">
<Fields>
<ext:ModelField Name="Id" Type="Int" SortDir="ASC" />
<ext:ModelField Name="Adi" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<TopBar>
<ext:Toolbar ID="Toolbar1" runat="server">
<Items>
<ext:Button ID="Button1" runat="server" Text="Pos ekle" Handler="addPlant" Icon="Add" />
</Items>
</ext:Toolbar>
</TopBar>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ID="Column7" runat="server" Text="Id" DataIndex="Id" Flex="1">
</ext:Column>
<ext:Column ID="Column8" runat="server" Text="Banka adı" DataIndex="Adi" Flex="1">
<Editor>
<ext:TextField ID="txtAd" runat="server" AllowBlank="false" />
</Editor>
</ext:Column>
<ext:ImageCommandColumn ID="ImageCommandColumn1" runat="server" Width="30" Sortable="false">
<Commands>
<ext:ImageCommand Icon="Decline" ToolTip-Text="Delete Plant" CommandName="delete">
</ext:ImageCommand>
</Commands>
<Listeners>
<Command Handler="this.up('gridpanel').store.removeAt(recordIndex);#{strPos}.sync();" />
</Listeners>
</ext:ImageCommandColumn>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="rowSelectionModel1" runat="server">
</ext:RowSelectionModel>
</SelectionModel>
<Plugins>
<ext:RowEditing ID="RowEditing1" runat="server" CancelBtnText="İptal" SaveBtnText="Kaydet" ClicksToEdit="0" SaveHandler="#{strPos}.sync();" >
</ext:RowEditing>
</Plugins>
</ext:GridPanel>
and the code behind is here
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
strPos.DataSource = ps.Getir();
strPos.DataBind();
}
}
protected void StoreChange_Event(object sender, EventArgs e)
{
strPos.DataSource = ps.Getir();
strPos.DataBind();
}
protected void store_change(object sender, AfterStoreChangedEventArgs e)
{
strPos.DataSource = ps.Getir();
strPos.DataBind();
}
public void StorePostEkle(object sender, BeforeRecordInsertedEventArgs e)
{
// string ss = e.Record.ToString();
Pos pss = e.Object<Pos>();
ps.Ekle(pss);
X.Msg.Notify("store", "storea veri eklendi" + e.Record).Show();
// GridPanel1.Reload();
}
protected void StorePosSil(object sender, BeforeRecordDeletedEventArgs e)
{
X.Msg.Notify("store", "storea dan veri, silindi " + e.Record).Show();
Pos pss = e.Object<Pos>();
try
{
ps.Sil(pss.Id);
}
catch (Exception)
{
throw;
}
}
protected void StorePostGuncelle(object sender, BeforeRecordUpdatedEventArgs e)
{
X.Msg.Notify("store", "storea güncellendi " + e.Record).Show();
Pos pss = e.Object<Pos>();
// Pos pss = JSON.Deserialize<Pos>(e.ToString());
ps.Guncelle(pss);

DevExpress AspxGridView filter in ObjectDataSource

Yet another problem with DevExpress AspxGridView :)
The context:
One Page
In the Page, a custom control
In the custom Control, a AspxDropDown
The AspxDropDown has a DropDownWindowTemplate
In the DropDownItemTemplate, I add a GridView and a paging/sorting/filtering enabled ObjectDataSource
When handling the selecting event of the ObjectDataSource, I should set filter parameters for the datasource. There filter parameters should come from the FilterRow of the AspxGridView (preferably using the AspxGridView.FilterExpression property).
The problem: the AspxGridView.FilterExpression property is not set to the proper values (set by the user).
Did anyone find a good implementation of what I'm trying to do here?
Thanks a bunch.
:)
I've finally managed to get around the problem.
Not a good solution, but, still, a way to work around it.
So.. The "solution" is to databind the grid on every AfterPerformCallback event.
void grid_AfterPerformCallback(object sender, ASPxGridViewAfterPerformCallbackEventArgs e)
{
((DevExpress.Web.ASPxGridView.ASPxGridView)sender).DataBind();
}
As I've said, it's not a good solution.
The answer per DevExpress is that the correct FilterExpression is updated when it is databound.
They allege that in BeforePerformDataSelect, you will see the correct value.
I have 1 grid that is hooked up to a SqlDataSource that is correctly doing this, and another that is not... So you're mileage may vary.
My second grid wasn't obeying this principal, so I integrated the other guy's concept rebinding in AfterPerformCallback(). The trick is to prevent double querying. This code also demonstrates how to hijack devexpress to build your own SQL. Obviously, this is from my working project, so use your imagination on functions that I have that you don't...
Here is the relevant html and code:
<dxwgv:ASPxGridView ID="grid" runat="server"
KeyFieldName="OrderID"
OnAfterPerformCallback="grid_AfterPerformCallback"
OnBeforePerformDataSelect="grid_BeforePerformDataSelect"
AutoGenerateColumns="True"
SettingsDetail-AllowOnlyOneMasterRowExpanded="true"
Settings-ShowFilterRow="true"
Settings-ShowFilterRowMenu="True"
SettingsBehavior-AllowSelectSingleRowOnly="true"
OnDetailRowExpandedChanged="Grid_DetailRowExpandedChanged"
Styles-Cell-Cursor="pointer"
SettingsBehavior-EnableRowHotTrack="true"
CssFilePath="~/App_Themes/Office2010Blue/{0}/styles.css"
CssPostfix="Office2010Blue"
SettingsPager-PageSize="<%# this._GridRowsPerPage %>"
SettingsBehavior-ColumnResizeMode="Control"
SettingsCustomizationWindow-PopupHorizontalAlign="WindowCenter"
SettingsCustomizationWindow-PopupVerticalAlign="WindowCenter"
SettingsCustomizationWindow-Width="300px"
Settings-ShowHorizontalScrollBar="true"
Width="<%# this._GetWidth() %>"
SettingsPager-AlwaysShowPager="true"
SettingsCookies-Enabled="true"
>
<Columns>
<dxwgv:GridViewDataColumn FieldName="PriorityType" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="basePatientID" Caption="PTID" />
<dxwgv:GridViewDataColumn FieldName="FirstName" />
<dxwgv:GridViewDataColumn FieldName="LastName" />
<dxwgv:GridViewDataColumn FieldName="Employer" />
<dxwgv:GridViewDataColumn FieldName="Insurer" />
<dxwgv:GridViewDataColumn FieldName="ClaimJurisdiction" Caption="Jurisdiction" />
<dxwgv:GridViewDataColumn FieldName="DOB" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="DateOfInjury" Caption="DOI" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="PostalCode" Caption="ZipCode" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="FirstCareDate" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="LastCareDate" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="IntakeStatus" />
<dxwgv:GridViewDataColumn FieldName="SchedulingNeeded" />
<dxwgv:GridViewDataColumn FieldName="InitialReferralDate" Caption="Date Assigned" />
<dxwgv:GridViewDataColumn FieldName="Orders_UpdatedOn" Caption="Last Follow-up" />
<dxwgv:GridViewDataColumn FieldName="RequestTypes" Caption="Service" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="FacilityGroups" Caption="Provider" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="ICD9Codes" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="CPTCodes" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="OrderCategory" Caption="Source" />
<dxwgv:GridViewDataColumn FieldName="CaseCoordinator" Visible="false" />
<dxwgv:GridViewDataColumn FieldName="SchedulingTier" Visible="false" Caption="Tier" />
<dxwgv:GridViewDataColumn FieldName="LockRequest_UserName" Visible="true" Caption="InUseBy" />
</Columns>
<Styles CssFilePath="~/App_Themes/Office2010Blue/{0}/styles.css" CssPostfix="Office2010Blue">
<Header ImageSpacing="5px" SortingImageSpacing="5px">
</Header>
<LoadingPanel ImageSpacing="10px">
</LoadingPanel>
</Styles>
<ImagesFilterControl>
<LoadingPanel Url="~/App_Themes/Office2010Blue/Editors/Loading.gif">
</LoadingPanel>
</ImagesFilterControl>
<Images SpriteCssFilePath="~/App_Themes/Office2010Blue/{0}/sprite.css">
<LoadingPanelOnStatusBar Url="~/App_Themes/Office2010Blue/GridView/gvLoadingOnStatusBar.gif">
</LoadingPanelOnStatusBar>
<LoadingPanel Url="~/App_Themes/Office2010Blue/GridView/Loading.gif">
</LoadingPanel>
</Images>
<ClientSideEvents ContextMenu="grid_ShowContextMenu" />
<ClientSideEvents BeginCallback="function(s, e) { OnBeginCallback(s,e); }" />
<ClientSideEvents EndCallback="function(s, e) { OnEndCallback(s,e); }" />
<StylesEditors>
<ProgressBar Height="25px">
</ProgressBar>
</StylesEditors>
</dxwgv:ASPxGridView>
<asp:SqlDataSource ID="GridSource" runat="server"></asp:SqlDataSource>
And here's the event handler for BeforePerformDataSelect:
private bool _DataBindingCompleted = false;
protected void grid_BeforePerformDataSelect(object sender, EventArgs e)
{
if (_DataBindCompleted) Grid_PerformDataSelect(sender, e);
}
protected override void Grid_PerformDataSelect(bool ClearSelection)
{
if (ClearSelection) this.grid.Selection.UnselectAll();
GridSource.ProviderName = System.Configuration.ConfigurationManager.ConnectionStrings["mysql"].ProviderName;
GridSource.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["mysql"].ConnectionString;
SetupSearch();
//if (this.FilterContext.Count > 0 || !string.IsNullOrEmpty(grid.FilterExpression))
//{
string FilterSQL = DevExpressUtils.GetMySQLFilterExpression(grid);
string OrderBySQL = DevExpressUtils.GetSQLOrderByExpression(grid, "OrderID");
//FilterSQL = FilterSQL.Replace("[PatientID]", "vwPatients."+ Patient.PRIMARYKEY);
if (Utils.GetAppSettingBool("MYSQL"))
{
GridSource.SelectCommand = this.MP.CurrentUser.GetEOSHeaderSQL(this.FilterContext, FilterSQL, "");
}
else
{
GridSource.SelectCommand = "";
}
}
protected override void Grid_PerformDataSelect(object sender, EventArgs e)
{
bool IsFromParent = this.ClientID.StartsWith(this.MP.GridCallback);
if (grid.Visible && (!this.Page.IsCallback ||
((this.MP.GridCallback == this.grid.ClientID && (this.MP.GridCallbackCommand != "SHOWDETAILROW" || this.IsDetailGrid))
|| (this.MP.GridCallbackCommand == "SHOWDETAILROW" && IsFromParent)
)
)
)
{
Grid_PerformDataSelect(false);
}
}
protected void grid_AfterPerformCallback(object sender, ASPxGridViewAfterPerformCallbackEventArgs e)
{
_DataBindCompleted = true;
((DevExpress.Web.ASPxGridView.ASPxGridView)sender).DataBind();
}
protected void Page_Init(object sender, EventArgs e)
{
grid.DataSource = GridSource;
}
protected new void Page_Load(object sender, EventArgs e)
{
this.grid.ClientInstanceName = this.grid.ClientID;
if (!this.IsPostBack)
{
_DataBindCompleted = true;
grid.DataBind();
}
}

Scrolling Pagination on Gridview via JQuery - Help

Having some problems with a solution that apparently works:
<script type="text/javascript" >
//following code utilizes jQuery 1.2.6
var prev = 0;
$(document).ready(
//DIV showing the message "Loading..." is hidden initially
//The message will be shown when records are fetched with AJAX
//when user has scrolled to the bottom of the DIV scrollbar
function() {
$(".divProgress").hide();
$(".divLeft").scroll(
function() {
//triggering point is when the difference of the heights of the TABLE
//and DIV match the DIV's scrollTop value
if ($('<%=grdPersonResults.ClientID %>').height() - this.scrollTop == $(this).height()) {
//progress bar
$(".divProgress").ajaxStart(function() {
$(this).show();
});
$(".divProgress").ajaxStop(function() {
$(this).hide();
});
//get last Order Id to track next fetch
var OrderIdLast = $('<%=grdPersonResults.ClientID %> tr:last').children("td:first").html();
//get last table row in order to append the new result set increment
var trLast = $('<%=grdPersonResults.ClientID %> tr:last');
if (parseInt(OrderIdLast, 10) > parseInt(prev, 10)) {
prev = OrderIdLast;
//make a async call to fetch the incremental results
$.post("AsyncHandler.ashx?lastOrderId=" + OrderIdLast, function(data) {
if (data != null) {
//append new result set to last row
trLast.after(data);
}
});
}
}
});
});
</script>
My Gridview is fairly simple:
<div class="divLeft">
<asp:GridView ID="grdPersonResults" AutoGenerateColumns="False" runat="server"
CellPadding="2" Width="100%" ForeColor="#333333" GridLines="None" BorderWidth="1px" BorderStyle="Solid"
BorderColor="Black" AllowSorting="True" CssClass="box-table-a">
<Columns>
<asp:HyperLinkField HeaderText="Name" SortExpression="NAME" DataNavigateUrlFields="EMPLOYEE_ID, COMPANY_ID, RNUM"
DataNavigateUrlFormatString="~/Admin/FinalizeEdit.aspx?id={0}&cid={1}&rnum={2}&action=EDIT" DataTextField="NAME" />
<asp:BoundField DataField="DESCRIPTION" HeaderText="Company" SortExpression="DESCRIPTION" />
<asp:BoundField DataField="SOURCE_ID" HeaderText="Source" SortExpression="SOURCE_ID" />
</Columns>
<FooterStyle CssClass="box-table-a" />
<RowStyle CssClass="box-table-a" />
<EditRowStyle CssClass="box-table-a" />
<SelectedRowStyle CssClass="box-table-a" />
<PagerStyle CssClass="box-table-a" />
<HeaderStyle CssClass="box-table-a" />
<AlternatingRowStyle CssClass="box-table-a" />
</asp:GridView>
</div>
<div class="divProgress">
Loading....
</div>
It doesn't ever seem to hit my AsyncHandler, not sure if my selectors are wrong since I'm using a Masterpage in ASP.net, but it seems to be picking up the elements.
change
if ($('<%=grdPersonResults.ClientID %>').height() - this.scrollTop == $(this).height()) {
to
if ($("#grdPersonResults").height() - this.scrollTop <= $(this).height()-2) {

Resources