I am having a problem performing paging and sorting on my ASP.net 2.0 page. I retrieve the data via a data access tool given to me which is pretty much an encrypted access to the database. Then I get the data retrieved from the database as seen in the IDataReader object and then pass it to a datatable. I use the datatable as the datasource for the gridview. I pasted my code below: Can you please tell me what I am doing wrong. I have pretty much followed every tutorial I have seen out there and I am just totally clueless now. Please help!!!
Default.aspx.cs
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
----------
----------
--
using System;
using System.Data;
using System.Configuration;
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 System.Windows.Forms;
using System.DirectoryServices;
using RaymondJames.PPRewriteMeth
ods;
using RaymondJames.Data;
using RaymondJames.RJEvtLR;
public partial class _Default : System.Web.UI.Page
{
private Microsoft.Practices.Enterp
riseLibrar
y.Data.Dat
abase _RjDatabase = RaymondJamesDatabaseFactor
y.CreateDa
tabase("Co
nnectToSer
ver");
private String sqlQuery = "";
private DataTable dtDataReader;
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
return;
UltraWebGrid1.Visible = false;
svcAcct.Visible = false;
rePopulate.Visible = false;
}
protected void Menu1_MenuItemClick(object
sender, MenuEventArgs e)
{
TextBox1.Text = "You just clicked the main menu ";
for (int i = 0; i < Menu1.Items.Count; i++)
{
for (int j = 0; j < Menu1.Items[i].ChildItems.
Count; j++)
{
if (Menu1.Items[i].ChildItems
[j].Select
ed)
{
TextBox1.Text = "You selected " + Menu1.Items[i].ChildItems[
j].Value;
switch(Menu1.Items[i].Chil
dItems[j].
Value.ToUp
per())
{
//case "OPEN":
// TextBox1.Text = "Open";
// break;
//case "CLOSE":
// TextBox1.Text = "close";
// break;
//case "SAVE AS":
// TextBox1.Text = "save as";
// break;
case "ACCOUNTS WITHOUT AN EMAIL ADDRESS":
sqlQuery = "SELECT user_name, used_email_addr, rj_expire_cd from cssnt.dbo.rj_password_exp where Len(used_email_addr) < 2 or used_email_addr is null or used_email_addr = '?'";
TextBox1.Text = "Accounts without an Email Address";
AssignDataSource(sqlQuery)
;
svcAcct.Visible = true;
rePopulate.Visible = true;
break;
case "ACCOUNTS WITH EXPIRED PASSWORD":
GridView1.DataSource = ArrayToDataTable(QueryAD.F
indExpired
Accounts(Q
ueryAD.Cal
culateNano
secondsFor
DateTime(D
ateTime.No
w.AddDays(
-90))));
break;
}
PopulateGrid();
}
}
}
}
private void AssignDataSource(String sqlStmt)
{
if (sqlStmt.Length > 0)
{
IDataReader sqldr = _RjDatabase.ExecuteReader(
CommandTyp
e.Text, sqlStmt);
GridView1.DataSource = DataReaderToDataTable(sqld
r);
}
}
private void PopulateGrid()
{
//UltraWebGrid1.DataSource
= sqldr;
//UltraWebGrid1.DisplayLay
out.Pager.
AllowPagin
g = true;
//UltraWebGrid1.DisplayLay
out.Pager.
PageSize = 20;
//UltraWebGrid1.DisplayLay
out.Pager.
Alignment = Infragistics.WebUI.UltraWe
bGrid.Page
rAlignment
.Center;
//UltraWebGrid1.DataBind()
;
//UltraWebGrid1.Visible = true;
GridView1.AllowSorting = true;
GridView1.AllowPaging = true;
GridView1.PageSize = 20;
GridView1.PagerSettings.Po
sition = PagerPosition.Bottom;
GridView1.DataBind();
GridView1.Visible = true;
TextBox1.Visible = true;
}
private DataTable DataReaderToDataTable(IDat
aReader input)
{
dtDataReader = new DataTable();
for (int i = 0; i < input.FieldCount; i++)
{
dtDataReader.Columns.Add(i
nput.GetNa
me(i), typeof(string));
}
while (input.Read())
{
DataRow dr = dtDataReader.NewRow();
for (int i = 0; i < input.FieldCount; i++)
{
dr[i] = input.GetValue(i);
}
dtDataReader.Rows.Add(dr);
}
TextBox1.Text = dtDataReader.Rows.Count + " records returned";
return dtDataReader;
}
private DataTable ArrayToDataTable(String[] input)
{
DataTable dtData = new DataTable();
dtData.Columns.Add("User Name", typeof(string));
dtData.Columns.Add("Passwo
rd Expiration Date", typeof(DateTime));
dtData.Columns.Add("Servic
e Account?", typeof(String));
DataRow dr = dtData.NewRow();
String isSvcAcct = "";
for (int i = 0; i < input.Length; i++)
{
DirectoryEntry de_user = QueryAD.RetrieveUserDirect
ory(input[
i]);
isSvcAcct = "No";
if (de_user.Properties.Contai
ns("rj-svc
-account")
)
{
isSvcAcct = "Yes";
}
dtData.Rows.Add(input[i], QueryAD.GetExpirationDate(
de_user), isSvcAcct);
}
TextBox1.Text = dtData.Rows.Count + " records returned";
dtDataReader = dtData;
return dtData;
}
protected void svcAcct_CheckedChanged(obj
ect sender, EventArgs e)
{
sqlQuery = "SELECT user_name, used_email_addr, rj_expire_cd from cssnt.dbo.rj_password_exp where (Len(used_email_addr) < 2 or used_email_addr is null or used_email_addr = '?')";
if (svcAcct.Checked == true)
{
sqlQuery = sqlQuery + " and rj_expire_cd < 96";
}
AssignDataSource(sqlQuery)
;
}
protected void GridView1_PageIndexChangin
g(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
}
protected void rePopulate_Click(object sender, EventArgs e)
{
GridView1.DataBind();
PopulateGrid();
}
protected void GridView1_PageIndexChanged
(object sender, EventArgs e)
{
DataView dv = new DataView(dtDataReader);
GridView1.DataSource = dv;
GridView1.DataBind();
PopulateGrid();
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
if (e.SortExpression == "user_name")
{
MessageBox.Show("You cannot sort by user name.");
e.Cancel = true;
}
e.SortDirection = System.Web.UI.WebControls.
SortDirect
ion.Descen
ding;
}
}
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
----------
----------
-
Default.aspx
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
----------
----------
-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<%@ Register Assembly="Infragistics.Web
UI.UltraWe
bGrid.Exce
lExport.v6
.2, Version=6.2.20062.34, Culture=neutral, PublicKeyToken=7dd5c3163f2
cd0cb"
Namespace="Infragistics.We
bUI.UltraW
ebGrid.Exc
elExport" TagPrefix="cc1" %>
<%@ Register Assembly="Infragistics.Web
UI.UltraWe
bGrid.v6.2
, Version=6.2.20062.34, Culture=neutral, PublicKeyToken=7dd5c3163f2
cd0cb"
Namespace="Infragistics.We
bUI.UltraW
ebGrid" TagPrefix="igtbl" %>
<%@ Register Assembly="Infragistics.Web
UI.UltraWe
bToolbar.v
6.2, Version=6.2.20062.34, Culture=neutral, PublicKeyToken=7dd5c3163f2
cd0cb"
Namespace="Infragistics.We
bUI.UltraW
ebToolbar"
TagPrefix="igtbar" %>
<%@ Register Assembly="Infragistics.Web
UI.UltraWe
bNavigator
.v6.2, Version=6.2.20062.34, Culture=neutral, PublicKeyToken=7dd5c3163f2
cd0cb"
Namespace="Infragistics.We
bUI.UltraW
ebNavigato
r" TagPrefix="ignav" %>
<%@ Register Assembly="Infragistics.Web
UI.Misc.v6
.2, Version=6.2.20062.34, Culture=neutral, PublicKeyToken=7dd5c3163f2
cd0cb"
Namespace="Infragistics.We
bUI.Misc" TagPrefix="igmisc" %>
<!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 bgcolor="#ffcc33">
<form id="WebForm1" method="post" runat="server">
<asp:Menu ID="Menu1" runat="server" BackColor="#FFFBD6" DynamicHorizontalOffset="2
"
Font-Bold="True" Font-Names="Verdana" Font-Overline="False" Font-Size="0.8em"
Font-Underline="True" ForeColor="#990000" Height="35px" OnMenuItemClick="Menu1_Men
uItemClick
"
Orientation="Horizontal" StaticSubMenuIndent="10px"
Width="740px">
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#990000" ForeColor="White" />
<DynamicMenuStyle BackColor="#FFFBD6" />
<StaticSelectedStyle BackColor="#FFCC66" />
<DynamicSelectedStyle BackColor="#FFCC66" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<Items>
<asp:MenuItem Text="File" Value="File">
<asp:MenuItem Text="Open" Value="Open"></asp:MenuIte
m>
<asp:MenuItem Text="Close" Value="Close"></asp:MenuIt
em>
<asp:MenuItem Text="Save As" Value="Save As"></asp:MenuItem>
<asp:MenuItem Text="Send To" Value="Send To"></asp:MenuItem>
<asp:MenuItem Text="Exit" Value="Exit"></asp:MenuIte
m>
</asp:MenuItem>
<asp:MenuItem Text="Edit" Value="Edit">
<asp:MenuItem Text="Copy" Value="Copy"></asp:MenuIte
m>
<asp:MenuItem Text="Paste" Value="Paste"></asp:MenuIt
em>
<asp:MenuItem Text="Select All" Value="Select All"></asp:MenuItem>
<asp:MenuItem Text="Find" Value="Find"></asp:MenuIte
m>
<asp:MenuItem Text="Go To" Value="Go To"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="Predefined" Value="Predefined">
<asp:MenuItem Text="Query a Specific Account" Value="Query a Specific Account"></asp:MenuItem>
<asp:MenuItem Text="Newly Added Account" Value="Newly Added Account"></asp:MenuItem>
<asp:MenuItem Text="Accounts with Expired Password" Value="Accounts with Expired Password">
</asp:MenuItem>
<asp:MenuItem Text="Accounts without an Email Address" Value="Accounts without an Email Address">
</asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="Customizable" Value="Customizable">
<asp:MenuItem Text="Create Customized Report" Value="Create Customized Report"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="Help" Value="Help"></asp:MenuIte
m>
</Items>
<StaticHoverStyle BackColor="#990000" ForeColor="White" />
</asp:Menu>
<cc1:UltraWebGridExcelExpo
rter ID="UltraWebGridExcelExpor
ter1" runat="server">
</cc1:UltraWebGridExcelExp
orter>
<asp:GridView ID="GridView1" runat="server" OnPageIndexChanging="GridV
iew1_PageI
ndexChangi
ng"
OnSorting="GridView1_Sorti
ng">
</asp:GridView>
<br />
<asp:TextBox ID="TextBox1" runat="server" Enabled="False" Width="573px"></asp:TextBo
x><br />
<igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" Height="488px" Width="732px">
<DisplayLayout AllowColSizingDefault="Fre
e" AllowColumnMovingDefault="
OnServer" AllowDeleteDefault="Yes"
AllowSortingDefault="OnCli
ent" AllowUpdateDefault="Yes" BorderCollapseDefault="Sep
arate"
HeaderClickActionDefault="
SortMulti"
Name="UltraWebGrid1" RowHeightDefault="20px"
RowSelectorsDefault="No" SelectTypeRowDefault="Exte
nded" Version="4.00" ViewType="OutlookGroupBy">
<GroupByBox>
<Style BackColor="ActiveBorder" BorderColor="Window"></Sty
le>
</GroupByBox>
<GroupByRowStyleDefault BackColor="Control" BorderColor="Window">
</GroupByRowStyleDefault>
<FooterStyleDefault BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">
<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" />
</FooterStyleDefault>
<RowStyleDefault BackColor="Window" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px">
<BorderDetails ColorLeft="Window" ColorTop="Window" />
<Padding Left="3px" />
</RowStyleDefault>
<FilterOptionsDefault AllString="(All)" EmptyString="(Empty)" NonEmptyString="(NonEmpty)
">
<FilterDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px"
CustomRules="overflow:auto
;" Font-Names="Verdana,Arial,
Helvetica,
sans-serif
"
Font-Size="11px" Width="200px">
<Padding Left="2px" />
</FilterDropDownStyle>
<FilterHighlightRowStyle BackColor="#151C55" ForeColor="White">
</FilterHighlightRowStyle>
</FilterOptionsDefault>
<HeaderStyleDefault BackColor="LightGray" BorderStyle="Solid" HorizontalAlign="Left">
<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" />
</HeaderStyleDefault>
<EditCellStyleDefault BorderStyle="None" BorderWidth="0px">
</EditCellStyleDefault>
<FrameStyle BackColor="Window" BorderColor="InactiveCapti
on" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Microsoft Sans Serif" Font-Size="8.25pt" Height="488px"
Width="732px">
</FrameStyle>
<Pager>
<Style BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">
<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px" ColorLeft="White"></Border
Details>
</Style>
</Pager>
<AddNewBox Hidden="False">
<Style BackColor="Window" BorderColor="InactiveCapti
on" BorderStyle="Solid" BorderWidth="1px">
<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px" ColorLeft="White"></Border
Details>
</Style>
</AddNewBox>
</DisplayLayout>
<Bands>
<igtbl:UltraGridBand>
<AddNewRow View="NotSet" Visible="NotSet">
</AddNewRow>
<FilterOptions AllString="" EmptyString="" NonEmptyString="">
<FilterDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px"
CustomRules="overflow:auto
;" Font-Names="Verdana,Arial,
Helvetica,
sans-serif
"
Font-Size="11px" Width="200px">
<Padding Left="2px" />
</FilterDropDownStyle>
<FilterHighlightRowStyle BackColor="#151C55" ForeColor="White">
</FilterHighlightRowStyle>
</FilterOptions>
</igtbl:UltraGridBand>
</Bands>
</igtbl:UltraWebGrid>
<asp:CheckBox ID="svcAcct" runat="server" OnCheckedChanged="svcAcct_
CheckedCha
nged"
Text="Remove Service Accounts" /> <br />
<asp:Button ID="rePopulate" runat="server" Text="Repopulate" Width="100px" OnClick="rePopulate_Click"
/>
</form>
</body>
</html>
Start Free Trial