Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
184
AJAX paging with grid created in code
posted

I am trying to create a webgrid control that can use AJAX to do paging back and forth.  I created the webgrid on an ASPX page and bound it to a dataset and then enabled AJAX and it pages OK using AJAX to populate the pages. 

I then tried to do the same thing generating the webgrid control in code behind, setting the properties of the webgrid to be the same as the properties that I found in the source of the ASPX page.  When I do this, the grid shows up OK when you load the page, but it doesn't page when I click the Next/Prev buttons - nothing happens at all. 

I tried putting a breakpoint in the IntializeDataSource event handler.  On the ASPX page where I add the webgrid via the designer, the event fires off every time I click the NEXT or PREV buttons on the pager.  But on the other ASPX page, where I added the grid through code-behind, the event handler is not firing.

 Anyone got any ideas?

Here's all the code:


InfragisticsGrid.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="InfragisticsGrid.aspx.cs" Inherits="MyTestWebApplication.InfragisticsGrid" %>

<%@ Register Assembly="Infragistics2.WebUI.UltraWebGrid.v8.1, Version=8.1.20081.1000, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"

Namespace="Infragistics.WebUI.UltraWebGrid" TagPrefix="igtbl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title></head>

<body>

<form id="form1" runat="server">

<!-- before grid -->

<div id="GridPlaceholder" runat="server">

 

</div>

<!-- after grid -->

</form></body>

</html>


InfragisticsGrid.aspx.cs

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using MyTestData.DataSetTableAdapters;

using MyTestData.Properties;

using Infragistics.WebUI.UltraWebGrid;

 

namespace MyTestWebApplication

{

public partial class InfragisticsGrid : System.Web.UI.Page

{

private UltraWebGrid _ultraWebGrid1;public UltraWebGrid UltraWebGrid1

{

get {

if (_ultraWebGrid1 == null)

{

_ultraWebGrid1 =
new UltraWebGrid();

}

return _ultraWebGrid1;

}

}

 

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

FormatGrid();

InitDataSource();

this.FindControl("GridPlaceholder").Controls.Add(UltraWebGrid1);

}

}

private void InitDataSource()

{

CommitteeTableAdapter ta = new CommitteeTableAdapter();

MyTestData.DataSet.CommitteeDataTable tbCommittee = ta.GetData();

DataView dvCommittee = new DataView(tbCommittee);dvCommittee.Sort = "ShortName";

UltraWebGrid1.DataSource = dvCommittee;

UltraWebGrid1.DataBind();

}

 

protected void UltraWebGrid1_InitializeDataSource(object sender, UltraGridEventArgs e)

{

InitDataSource();

}

 

private void FormatGrid()

{

// General properties - set up AJAX paging

UltraWebGrid1.ID = "UltraWebGrid";

UltraWebGrid1.Browser = BrowserLevel.Xml;

UltraWebGrid1.EnableTheming = false;

UltraWebGrid1.Width = Unit.Percentage(100.0);

UltraWebGrid1.InitializeDataSource += new InitializeDataSourceEventHandler(UltraWebGrid1_InitializeDataSource);

// Display-related properties

UltraGridLayout layout = UltraWebGrid1.DisplayLayout;

layout.Name = "GridLayout";

layout.AllowSortingDefault = AllowSorting.OnClient;

layout.AllowColSizingDefault = AllowSizing.Free;

layout.TableLayout = TableLayout.Fixed;

layout.RowSelectorsDefault = RowSelectors.No;

layout.AllowColumnMovingDefault = AllowColumnMoving.None;

layout.HeaderClickActionDefault = HeaderClickAction.SortSingle;

layout.StationaryMargins = StationaryMargins.Header;

layout.BorderCollapseDefault = BorderCollapse.Separate;

layout.AutoGenerateColumns = false;

layout.LoadOnDemand = LoadOnDemand.Xml;

layout.Section508Compliant = true;layout.FrameStyle.Width = Unit.Percentage(100.0);

 

// Add one column

UltraWebGrid1.Bands.Add(new UltraGridBand());

UltraGridColumn column = new UltraGridColumn(); //"ShortName", "Short Name", ColumnType.NotSet, ""); //();

column.BaseColumnName = "ShortName";

column.Key = "ShortName";

column.Width = Unit.Percentage(100.0);

column.ValueList.DisplayMember = "ShortName";

column.Header.Caption = "Short Name";

UltraWebGrid1.Columns.Add(column);

// Paging

layout.Pager.MinimumPagesForDisplay = 1;

layout.Pager.PageSize = 5;

layout.Pager.AllowPaging =
true;

layout.Pager.ChangeLinksColor = false;

layout.Pager.NextText = "Next";

layout.Pager.PrevText = "Previous";

layout.Pager.StyleMode = PagerStyleMode.PrevNext;

// Not sure if I need this...

layout.ActivationObject.BorderColor = System.Drawing.Color.Empty;layout.ActivationObject.BorderWidth = Unit.Empty;

}

 

}

}

 

 

 


Infragistics2.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="InfragristicsGrid2.aspx.cs" Inherits="MyTestWebApplication.InfragristicsGrid2" %>

<%@ Register Assembly="Infragistics2.WebUI.UltraWebGrid.v8.1, Version=8.1.20081.1000, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"

Namespace="Infragistics.WebUI.UltraWebGrid" TagPrefix="igtbl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title></head>

<body>

<form id="form1" runat="server">

<div>

<igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" Width="905px" Height="238px" Browser="Xml" OnInitializeDataSource="UltraWebGrid1_InitializeDataSource">

<Bands>

<igtbl:UltraGridBand>

<AddNewRow View="NotSet" Visible="NotSet">

</AddNewRow>

</igtbl:UltraGridBand>

</Bands>

<DisplayLayout AllowColSizingDefault="Free"

AllowSortingDefault="OnClient" BorderCollapseDefault="Separate"

HeaderClickActionDefault="SortSingle" Name="UltraWebGrid1" RowHeightDefault="20px"

RowSelectorsDefault="No" TableLayout="Fixed" Version="4.00" UseFixedHeaders="True" LoadOnDemand="Xml">

<Pager MinimumPagesForDisplay="2" AllowPaging="True" StyleMode="PrevNext" PageSize="10">

</Pager>

<FrameStyle Height="238px" Width="905px">

</FrameStyle>

</DisplayLayout>

</igtbl:UltraWebGrid>

</div>

</form></body>

</html>


Infragistics2.aspx.cs

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using MyTestData.DataSetTableAdapters;

using MyTestData.Properties;

namespace MyTestWebApplication

{

public partial class InfragristicsGrid2 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

InitDataSource();

}

private void InitDataSource()

{

CommitteeTableAdapter ta = new CommitteeTableAdapter();

MyTestData.DataSet.CommitteeDataTable tbCommittee = ta.GetData();

DataView dvCommittee = new DataView(tbCommittee);dvCommittee.Sort = "ShortName";

UltraWebGrid1.DataSource = dvCommittee;

UltraWebGrid1.DataBind();

}

protected void UltraWebGrid1_InitializeDataSource(object sender, Infragistics.WebUI.UltraWebGrid.UltraGridEventArgs e)

{

InitDataSource();

}

}

}