DataGrid not paging

H

Hanz

I did what this article
(http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/vbcon/html/vbtskspecifyingpagingbehaviorindatagridwebcon
trol.asp) says to do in the Using Default Paging with
Default Navigation Controls section and when using the
event hits databind() i recieve the following error...
Invalid CurrentPageIndex value. It must be >= 0 and < the
PageCount.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and where
it originated in the code.

Exception Details: System.Web.HttpException: Invalid
CurrentPageIndex value. It must be >= 0 and < the
PageCount.

Source Error:


Line 139: {
Line 140: DataGrid1.CurrentPageIndex
= e.NewPageIndex;
Line 141: DataGrid1.DataBind();
Line 142: }
Line 143: }

Source File: c:\inetpub\wwwroot\voc\vocadmin.aspx.cs
Line: 141


need some help plz ....

here's the class code ...

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace VoiceOfCustomer
{
/// <summary>
/// Summary description for vocAdmin.
/// </summary>
public class vocAdmin : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.DropDownList drpApp;
protected
System.Web.UI.WebControls.DataGrid DataGrid1;
protected
System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand
sqlSelectCommand1;
protected
System.Data.SqlClient.SqlConnection sqlConnection1;
protected VoiceOfCustomer.DataSet1
dataSet11;
protected System.Web.UI.WebControls.Label
Label2;
protected
System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.Label
Label1;

private void Page_Load(object sender,
System.EventArgs e)
{
fillAppDrpDwn();

if (!Page.IsPostBack)
{
try
{

sqlDataAdapter1.Fill(dataSet11);
DataGrid1.DataBind
();
}
catch
{
Label2.Text
= "Unable to connect to database! DATAGRID will not be
loaded!";
}
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required
by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new
System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new
System.Data.SqlClient.SqlConnection();
this.dataSet11 = new
VoiceOfCustomer.DataSet1();

((System.ComponentModel.ISupportInitialize)
(this.dataSet11)).BeginInit();
this.DataGrid1.PageIndexChanged +=
new
System.Web.UI.WebControls.DataGridPageChangedEventHandler
(this.DataGrid1_PageIndexChanged);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand
= this.sqlSelectCommand1;

this.sqlDataAdapter1.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {



new
System.Data.Common.DataTableMapping
("Table", "dbo.VocSelSurveyItemsGrid", new
System.Data.Common.DataColumnMapping[] {








new System.Data.Common.DataColumnMapping
("SurveyID", "SurveyID"),








new System.Data.Common.DataColumnMapping
("SurveyDesc", "SurveyDesc"),








new System.Data.Common.DataColumnMapping
("ApplicationDesc", "ApplicationDesc"),








new System.Data.Common.DataColumnMapping("PubDt", "PubDt"),








new System.Data.Common.DataColumnMapping
("LastUpdate", "LastUpdate"),








new System.Data.Common.DataColumnMapping
("InputType", "InputType"),








new System.Data.Common.DataColumnMapping
("InputName", "InputName"),








new System.Data.Common.DataColumnMapping
("MaxLength", "MaxLength"),








new System.Data.Common.DataColumnMapping
("OrderNum", "OrderNum"),








new System.Data.Common.DataColumnMapping("Style", "Style"),








new System.Data.Common.DataColumnMapping("Qty", "Qty")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText
= "dbo.[VocSelSurveyItemsGrid]";
this.sqlSelectCommand1.CommandType
= System.Data.CommandType.StoredProcedure;
this.sqlSelectCommand1.Connection
= this.sqlConnection1;

this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4,
System.Data.ParameterDirection.ReturnValue, false,
((System.Byte)(10)), ((System.Byte)(0)), "",
System.Data.DataRowVersion.Current, null));
//
// sqlConnection1
//

this.sqlConnection1.ConnectionString = "data
source=risk01;initial
catalog=prd_riskim;password=changeit;persist security " +
"info=True;user
id=riskimuser;workstation id=B000BCD00BAD8;packet
size=4096";
//
// dataSet11
//
this.dataSet11.DataSetName
= "DataSet1";
this.dataSet11.Locale = new
System.Globalization.CultureInfo("en-US");
this.dataSet11.Namespace
= "http://www.tempuri.org/DataSet1.xsd";
this.Load += new
System.EventHandler(this.Page_Load);

((System.ComponentModel.ISupportInitialize)
(this.dataSet11)).EndInit();

}
#endregion


#region Fill application drop down

void fillAppDrpDwn()
{
string myConn="";
if(myConn == "")
{
myConn =
this.sqlConnection1.ConnectionString;
//myConn
= "Database=prd_riskim;Server=risk01;Integrated
Security=false;User ID=riskimuser;pwd=changeit;";
}
SqlConnection SqlConn = new
SqlConnection(myConn);
SqlDataAdapter SqlAdapt = new
SqlDataAdapter("select * from vocapplications", SqlConn);
DataSet dsvocApps = new DataSet();
SqlAdapt.Fill
(dsvocApps, "VOCApplications");
drpApp.DataSource =
dsvocApps.Tables["VOCApplications"].DefaultView;
try
{
drpApp.DataBind();
}
catch
{
Label2.Text = "Unable to
connect to database! DropDown will not be loaded!";
}
}
#endregion

private void DataGrid1_PageIndexChanged
(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex =
e.NewPageIndex;
DataGrid1.DataBind();
}
}
}
 
B

BigJim61

The problem is that the documentation left out one major important
item:


Line 140: DataGrid1.CurrentPageIndex = e.NewPageIndex;
Line 141: DataGrid1.DataBind();

in between lines 140 and 141 you need to repopulate your dataset.

Hope This Helps!
I did what this article
(http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/vbcon/html/vbtskspecifyingpagingbehaviorindatagridwebcon
trol.asp) says to do in the Using Default Paging with
Default Navigation Controls section and when using the
event hits databind() i recieve the following error...
Invalid CurrentPageIndex value. It must be >= 0 and < the
PageCount.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and where
it originated in the code.

Exception Details: System.Web.HttpException: Invalid
CurrentPageIndex value. It must be >= 0 and < the
PageCount.

Source Error:


Line 139: {
Line 140: DataGrid1.CurrentPageIndex
= e.NewPageIndex;
Line 141: DataGrid1.DataBind();
Line 142: }
Line 143: }

Source File: c:\inetpub\wwwroot\voc\vocadmin.aspx.cs
Line: 141


need some help plz ....

here's the class code ...

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace VoiceOfCustomer
{
/// <summary>
/// Summary description for vocAdmin.
/// </summary>
public class vocAdmin : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.DropDownList drpApp;
protected
System.Web.UI.WebControls.DataGrid DataGrid1;
protected
System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand
sqlSelectCommand1;
protected
System.Data.SqlClient.SqlConnection sqlConnection1;
protected VoiceOfCustomer.DataSet1
dataSet11;
protected System.Web.UI.WebControls.Label
Label2;
protected
System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.Label
Label1;

private void Page_Load(object sender,
System.EventArgs e)
{
fillAppDrpDwn();

if (!Page.IsPostBack)
{
try
{

sqlDataAdapter1.Fill(dataSet11);
DataGrid1.DataBind
();
}
catch
{
Label2.Text
= "Unable to connect to database! DATAGRID will not be
loaded!";
}
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required
by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new
System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new
System.Data.SqlClient.SqlConnection();
this.dataSet11 = new
VoiceOfCustomer.DataSet1();

((System.ComponentModel.ISupportInitialize)
(this.dataSet11)).BeginInit();
this.DataGrid1.PageIndexChanged +=
new
System.Web.UI.WebControls.DataGridPageChangedEventHandler
(this.DataGrid1_PageIndexChanged);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand
= this.sqlSelectCommand1;

this.sqlDataAdapter1.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {



new
System.Data.Common.DataTableMapping
("Table", "dbo.VocSelSurveyItemsGrid", new
System.Data.Common.DataColumnMapping[] {








new System.Data.Common.DataColumnMapping
("SurveyID", "SurveyID"),








new System.Data.Common.DataColumnMapping
("SurveyDesc", "SurveyDesc"),








new System.Data.Common.DataColumnMapping
("ApplicationDesc", "ApplicationDesc"),








new System.Data.Common.DataColumnMapping("PubDt", "PubDt"),








new System.Data.Common.DataColumnMapping
("LastUpdate", "LastUpdate"),








new System.Data.Common.DataColumnMapping
("InputType", "InputType"),








new System.Data.Common.DataColumnMapping
("InputName", "InputName"),








new System.Data.Common.DataColumnMapping
("MaxLength", "MaxLength"),








new System.Data.Common.DataColumnMapping
("OrderNum", "OrderNum"),








new System.Data.Common.DataColumnMapping("Style", "Style"),








new System.Data.Common.DataColumnMapping("Qty", "Qty")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText
= "dbo.[VocSelSurveyItemsGrid]";
this.sqlSelectCommand1.CommandType
= System.Data.CommandType.StoredProcedure;
this.sqlSelectCommand1.Connection
= this.sqlConnection1;

this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4,
System.Data.ParameterDirection.ReturnValue, false,
((System.Byte)(10)), ((System.Byte)(0)), "",
System.Data.DataRowVersion.Current, null));
//
// sqlConnection1
//

this.sqlConnection1.ConnectionString = "data
source=risk01;initial
catalog=prd_riskim;password=changeit;persist security " +
"info=True;user
id=riskimuser;workstation id=B000BCD00BAD8;packet
size=4096";
//
// dataSet11
//
this.dataSet11.DataSetName
= "DataSet1";
this.dataSet11.Locale = new
System.Globalization.CultureInfo("en-US");
this.dataSet11.Namespace
= "http://www.tempuri.org/DataSet1.xsd";
this.Load += new
System.EventHandler(this.Page_Load);

((System.ComponentModel.ISupportInitialize)
(this.dataSet11)).EndInit();

}
#endregion


#region Fill application drop down

void fillAppDrpDwn()
{
string myConn="";
if(myConn == "")
{
myConn =
this.sqlConnection1.ConnectionString;
//myConn
= "Database=prd_riskim;Server=risk01;Integrated
Security=false;User ID=riskimuser;pwd=changeit;";
}
SqlConnection SqlConn = new
SqlConnection(myConn);
SqlDataAdapter SqlAdapt = new
SqlDataAdapter("select * from vocapplications", SqlConn);
DataSet dsvocApps = new DataSet();
SqlAdapt.Fill
(dsvocApps, "VOCApplications");
drpApp.DataSource =
dsvocApps.Tables["VOCApplications"].DefaultView;
try
{
drpApp.DataBind();
}
catch
{
Label2.Text = "Unable to
connect to database! DropDown will not be loaded!";
}
}
#endregion

private void DataGrid1_PageIndexChanged
(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex =
e.NewPageIndex;
DataGrid1.DataBind();
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top