Advertisement

04.18.2007 at 01:34PM PDT, ID: 22519826
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.2

GridView: Paging and sorting issues

Asked by fin_comp in C# Programming Language, Programming for ASP.NET, WebApplications

Tags: , ,

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.PPRewriteMethods;
using RaymondJames.Data;
using RaymondJames.RJEvtLR;

public partial class _Default : System.Web.UI.Page
{
    private Microsoft.Practices.EnterpriseLibrary.Data.Database _RjDatabase = RaymondJamesDatabaseFactory.CreateDatabase("ConnectToServer");
    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].Selected)
                {
                    TextBox1.Text = "You selected " + Menu1.Items[i].ChildItems[j].Value;
                    switch(Menu1.Items[i].ChildItems[j].Value.ToUpper())
                    {
                        //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.FindExpiredAccounts(QueryAD.CalculateNanosecondsForDateTime(DateTime.Now.AddDays(-90))));
                            break;
                    }
                    PopulateGrid();
                }
            }
        }
    }
    private void AssignDataSource(String sqlStmt)
    {
        if (sqlStmt.Length > 0)
        {
            IDataReader sqldr = _RjDatabase.ExecuteReader(CommandType.Text, sqlStmt);
            GridView1.DataSource = DataReaderToDataTable(sqldr);
        }
    }
    private void PopulateGrid()
    {

       
        //UltraWebGrid1.DataSource = sqldr;
        //UltraWebGrid1.DisplayLayout.Pager.AllowPaging = true;
        //UltraWebGrid1.DisplayLayout.Pager.PageSize = 20;
        //UltraWebGrid1.DisplayLayout.Pager.Alignment = Infragistics.WebUI.UltraWebGrid.PagerAlignment.Center;
        //UltraWebGrid1.DataBind();
        //UltraWebGrid1.Visible = true;
       

        GridView1.AllowSorting = true;
        GridView1.AllowPaging = true;
        GridView1.PageSize = 20;
        GridView1.PagerSettings.Position = PagerPosition.Bottom;
        GridView1.DataBind();
        GridView1.Visible = true;
        TextBox1.Visible = true;
    }
    private DataTable DataReaderToDataTable(IDataReader input)
    {
       dtDataReader = new DataTable();
        for (int i = 0; i < input.FieldCount; i++)
        {
            dtDataReader.Columns.Add(input.GetName(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("Password Expiration Date", typeof(DateTime));
        dtData.Columns.Add("Service Account?", typeof(String));
        DataRow dr = dtData.NewRow();
        String isSvcAcct = "";
        for (int i = 0; i < input.Length; i++)
        {
            DirectoryEntry de_user = QueryAD.RetrieveUserDirectory(input[i]);
            isSvcAcct = "No";
            if (de_user.Properties.Contains("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(object 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_PageIndexChanging(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.SortDirection.Descending;
       
    }
}





-------------------------------------------------------------------------------------------------------------------------------
Default.aspx
-------------------------------------------------------------------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="Infragistics.WebUI.UltraWebGrid.ExcelExport.v6.2, Version=6.2.20062.34, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
    Namespace="Infragistics.WebUI.UltraWebGrid.ExcelExport" TagPrefix="cc1" %>
<%@ Register Assembly="Infragistics.WebUI.UltraWebGrid.v6.2, Version=6.2.20062.34, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
    Namespace="Infragistics.WebUI.UltraWebGrid" TagPrefix="igtbl" %>

<%@ Register Assembly="Infragistics.WebUI.UltraWebToolbar.v6.2, Version=6.2.20062.34, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
    Namespace="Infragistics.WebUI.UltraWebToolbar" TagPrefix="igtbar" %>
<%@ Register Assembly="Infragistics.WebUI.UltraWebNavigator.v6.2, Version=6.2.20062.34, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
    Namespace="Infragistics.WebUI.UltraWebNavigator" TagPrefix="ignav" %>
<%@ Register Assembly="Infragistics.WebUI.Misc.v6.2, Version=6.2.20062.34, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
    Namespace="Infragistics.WebUI.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_MenuItemClick"
                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:MenuItem>
                        <asp:MenuItem Text="Close" Value="Close"></asp:MenuItem>
                        <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:MenuItem>
                    </asp:MenuItem>
                    <asp:MenuItem Text="Edit" Value="Edit">
                        <asp:MenuItem Text="Copy" Value="Copy"></asp:MenuItem>
                        <asp:MenuItem Text="Paste" Value="Paste"></asp:MenuItem>
                        <asp:MenuItem Text="Select All" Value="Select All"></asp:MenuItem>
                        <asp:MenuItem Text="Find" Value="Find"></asp:MenuItem>
                        <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:MenuItem>
                </Items>
                <StaticHoverStyle BackColor="#990000" ForeColor="White" />
            </asp:Menu>
            <cc1:UltraWebGridExcelExporter ID="UltraWebGridExcelExporter1" runat="server">
            </cc1:UltraWebGridExcelExporter>
            &nbsp; &nbsp; &nbsp;
            &nbsp;
            &nbsp;<asp:GridView ID="GridView1" runat="server" OnPageIndexChanging="GridView1_PageIndexChanging"
                OnSorting="GridView1_Sorting">
            </asp:GridView>
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
            <br />
            <asp:TextBox ID="TextBox1" runat="server" Enabled="False" Width="573px"></asp:TextBox><br />
            &nbsp;
            <igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" Height="488px" Width="732px">
                <DisplayLayout AllowColSizingDefault="Free" AllowColumnMovingDefault="OnServer" AllowDeleteDefault="Yes"
                    AllowSortingDefault="OnClient" AllowUpdateDefault="Yes" BorderCollapseDefault="Separate"
                    HeaderClickActionDefault="SortMulti" Name="UltraWebGrid1" RowHeightDefault="20px"
                    RowSelectorsDefault="No" SelectTypeRowDefault="Extended" Version="4.00" ViewType="OutlookGroupBy">
                    <GroupByBox>
                        <Style BackColor="ActiveBorder" BorderColor="Window"></Style>
                    </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="InactiveCaption" 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"></BorderDetails>
</Style>
                    </Pager>
                    <AddNewBox Hidden="False">
                        <Style BackColor="Window" BorderColor="InactiveCaption" BorderStyle="Solid" BorderWidth="1px">
<BorderDetails ColorTop="White" WidthLeft="1px" WidthTop="1px" ColorLeft="White"></BorderDetails>
</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>
            &nbsp;
            &nbsp;
            <asp:CheckBox ID="svcAcct" runat="server" OnCheckedChanged="svcAcct_CheckedChanged"
                Text="Remove Service Accounts" />&nbsp;&nbsp;<br />
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
            <asp:Button ID="rePopulate" runat="server" Text="Repopulate" Width="100px" OnClick="rePopulate_Click" />
            </form>
      </body>
</html>
Start Free Trial
[+][-]04.18.2007 at 01:42PM PDT, ID: 18935018

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.18.2007 at 01:47PM PDT, ID: 18935053

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.18.2007 at 04:40PM PDT, ID: 18935916

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.19.2007 at 06:42AM PDT, ID: 18938887

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.19.2007 at 06:45AM PDT, ID: 18938913

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.19.2007 at 06:49AM PDT, ID: 18938948

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C# Programming Language, Programming for ASP.NET, WebApplications
Tags: gridview, paging, ultrawebgrid
Sign Up Now!
Solution Provided By: VICKRAM
Participating Experts: 1
Solution Grade: B
 
 
[+][-]04.19.2007 at 07:10AM PDT, ID: 18939118

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.19.2007 at 07:34AM PDT, ID: 18939321

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43