HawaiiDragon
asked on
Can't get DataGrid to page. in C#
hello experts,
I am having a heck of a time with a datagrid. This datagrid gets populated on a button click with results from a database. I want the datagrid to display the first 10 results and then be able to "page" to the next results and so on...... I can get the datagrid to page but other than that I cant get the darn thing to work for anything....
in the DataGrid1 Propertis page I have allow paging and allow custom paging selected with the page siae = 10. Show navigation buttons is selected as well... what am I doing wrong.
I am having a heck of a time with a datagrid. This datagrid gets populated on a button click with results from a database. I want the datagrid to display the first 10 results and then be able to "page" to the next results and so on...... I can get the datagrid to page but other than that I cant get the darn thing to work for anything....
in the DataGrid1 Propertis page I have allow paging and allow custom paging selected with the page siae = 10. Show navigation buttons is selected as well... what am I doing wrong.
<asp:DataGrid ID="DataGrid1" runat="server" AllowPaging="True"
AllowSorting="True" ShowFooter="True" AllowCustomPaging="True">
<PagerStyle NextPageText=">" PrevPageText="<" BackColor="#FFCC66"
ForeColor="#333333" HorizontalAlign="Center" />
</asp:DataGrid>
ASKER
how would I do this in C# I dont know VB
private void GridPageIndexChanged(objec t source, System.Web.UI.WebControls. DataGridPa geChangedE ventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
//Bind the DataGrid again with the Data Source
DataGrid1.DataSource = dataSet1;
DataGrid1.DataBind();
}
{
DataGrid1.CurrentPageIndex
//Bind the DataGrid again with the Data Source
DataGrid1.DataSource = dataSet1;
DataGrid1.DataBind();
}
In C#
private void GridPageIndexChanged(objec t sender, System.Web.UI.WebControls. DataGridPa geChangedE ventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
//Bind the DataGrid again with the Data Source
DataGrid1.DataSource = dataSet1;
DataGrid1.DataBind();
}
private void GridPageIndexChanged(objec
{
DataGrid1.CurrentPageIndex
//Bind the DataGrid again with the Data Source
DataGrid1.DataSource = dataSet1;
DataGrid1.DataBind();
}
ASKER
this is how I have it working... I tried to put your solustion in and it does not llike it.... and its in a public function.... I cant figure out why it wont use it.
public void work()
{
System.Data.SqlClient.SqlConnection con4 = new System.Data.SqlClient.SqlConnection();
con4.ConnectionString = ConfigurationManager.ConnectionStrings["strDBCourseStandard"].ConnectionString;
con4.Open();
string strSQL = "Select distinct * from schedule Where SchoolYear = 2008";
SqlCommand objCommand = new SqlCommand(strSQL, con4);
SqlDataReader objReader = objCommand.ExecuteReader();
DataGrid1.DataSource = objReader;
DataGrid1.DataBind();
objReader.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
smash();
work();
working2();
}
private void GridPageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
//Bind the DataGrid again with the Data Source
DataGrid1.DataSource = objreader; <---- it does not like the datasourse...... any Ideas?
DataGrid1.DataBind();
}
In a web based application, an objects lifetime is only during one execution. Once the page gets rendered and the user initiates another postback... object that were created on a prior call are no longer accessible. You need to recreate the reader object (or otherwise store it in a session variable - and should you decide to take this approach ... rather use a dataset as opposed to a datareader).
Try changing the GridPageIndexChanged method to this:
private void GridPageIndexChanged(objec t sender, System.Web.UI.WebControls. DataGridPa geChangedE ventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
work();
}
'Also make sure that you have changed the ASPX file accordingly (the part in BOLD in one of my previous posts here).
Try changing the GridPageIndexChanged method to this:
private void GridPageIndexChanged(objec
{
DataGrid1.CurrentPageIndex
work();
}
'Also make sure that you have changed the ASPX file accordingly (the part in BOLD in one of my previous posts here).
ASKER
This is the error I am getting now.....
Error 3 'System.EventArgs' does not contain a definition for 'NewPageIndex' and no extension method 'NewPageIndex' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\rshier\My Documents\Visual Studio 2008\ClassSchedules\RealDa taGridDele teMe3YouBe tterFuckin gWork.aspx .cs 43 40 C:\...\ClassSchedules\
ASPXCDE
_________________
<asp:DataGrid ID="DataGrid1" runat="server" AllowCustomPaging="True"
AllowPaging="True" PageSize="10" AllowSorting="True"
onselectedindexchanged="Da taGrid1_Se lectedInde xChanged" ShowFooter="True">
<PagerStyle Mode="NumericPages" HorizontalAlign="Right" />
</asp:DataGrid>
Codebhind (cs)
__________________________
using System;
using System.Configuration;
using System.Data.SqlClient;
public partial class RealDataGridDeleteMe3YouBe tterFuckin gWork : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
public void work()
{
System.Data.SqlClient.SqlC onnection con4 = new System.Data.SqlClient.SqlC onnection( );
con4.ConnectionString = ConfigurationManager.Conne ctionStrin gs["strDBC ourseStand ard"].Conn ectionStri ng;
con4.Open();
string strSQL = "Select Distinct * from ClassScheduleView where SchoolYear = 2010 and Course_Abb = 'AR202' and Semester = 'F2Y2010' and Syllabus = 'Created - Approved' and Campus_Name = 'Fort Bliss'";
SqlCommand objCommand = new SqlCommand(strSQL, con4);
SqlDataReader objReader = objCommand.ExecuteReader() ;
DataGrid1.VirtualItemCount = 10000;
DataGrid1.DataSource = objReader;
DataGrid1.DataBind();
objReader.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
work();
}
protected void DataGrid1_SelectedIndexCha nged(objec t sender, EventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
work();
}
}
please tell me why i am gettir errs for no extension methods
------- second error
Error 6 'ASP.realdatagriddeleteme3 youbetterf uckingwork _aspx' does not contain a definition for 'GridPageIndexChanged' and no extension method 'GridPageIndexChanged' accepting a first argument of type 'ASP.realdatagriddeleteme3 youbetterf uckingwork _aspx' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\rshier\My Documents\Visual Studio 2008\ClassSchedules\RealDa taGridDele teMe3YouBe tterFuckin gWork.aspx 1 1 C:\...\ClassSchedules\
Error 3 'System.EventArgs' does not contain a definition for 'NewPageIndex' and no extension method 'NewPageIndex' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\rshier\My Documents\Visual Studio 2008\ClassSchedules\RealDa
ASPXCDE
_________________
<asp:DataGrid ID="DataGrid1" runat="server" AllowCustomPaging="True"
AllowPaging="True" PageSize="10" AllowSorting="True"
onselectedindexchanged="Da
<PagerStyle Mode="NumericPages" HorizontalAlign="Right" />
</asp:DataGrid>
Codebhind (cs)
__________________________
using System;
using System.Configuration;
using System.Data.SqlClient;
public partial class RealDataGridDeleteMe3YouBe
{
protected void Page_Load(object sender, EventArgs e)
{ }
public void work()
{
System.Data.SqlClient.SqlC
con4.ConnectionString = ConfigurationManager.Conne
con4.Open();
string strSQL = "Select Distinct * from ClassScheduleView where SchoolYear = 2010 and Course_Abb = 'AR202' and Semester = 'F2Y2010' and Syllabus = 'Created - Approved' and Campus_Name = 'Fort Bliss'";
SqlCommand objCommand = new SqlCommand(strSQL, con4);
SqlDataReader objReader = objCommand.ExecuteReader()
DataGrid1.VirtualItemCount
DataGrid1.DataSource = objReader;
DataGrid1.DataBind();
objReader.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
work();
}
protected void DataGrid1_SelectedIndexCha
{
DataGrid1.CurrentPageIndex
work();
}
}
please tell me why i am gettir errs for no extension methods
------- second error
Error 6 'ASP.realdatagriddeleteme3
protected void DataGrid1_SelectedIndexCha nged(objec t sender, EventArgs e)
should be:
protected void DataGrid1_SelectedIndexCha nged(objec t sender, DataGridPageChangedEventAr gs e)
you are using the wrong event. See comment 33559721
should be:
protected void DataGrid1_SelectedIndexCha
you are using the wrong event. See comment 33559721
ASKER
Now I am getting this error
-------------------------- ---------- ---
Error 4 No overload for 'DataGrid1_SelectedIndexCh anged' matches delegate 'System.EventHandler' C:\Documents and Settings\rshier\My Documents\Visual Studio 2008\ClassSchedules\RealDa taGridDele teMe3YouBe tterFuckin gWork.aspx 1 1 C:\...\ClassSchedules\
-------------------------- ---------- ---------- ----
aspx code
-------------------------- -
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RealDataGridDele teMe3YouBe tterFuckin gWork.aspx .cs" Inherits="RealDataGridDele teMe3YouBe tterFuckin gWork" %>
<!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>
<br />
<br />
<asp:DataGrid ID="DataGrid1" runat="server" AllowCustomPaging="True"
AllowPaging="True" PageSize="10" AllowSorting="True"
OnPageIndexChanged="GridPa geIndexCha nged" onselectedindexchanged="Da taGrid1_Se lectedInde xChanged" ShowFooter="True">
<PagerStyle Mode="NumericPages" HorizontalAlign="Right" />
</asp:DataGrid>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
<p>
</p>
</body>
</html>
-------------------------- ----------
cs code
-------------------------- -
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.UI.WebControls. Adapters;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls. WebParts;
public partial class RealDataGridDeleteMe3YouBe tterFuckin gWork : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
public void work()
{
System.Data.SqlClient.SqlC onnection con4 = new System.Data.SqlClient.SqlC onnection( );
con4.ConnectionString = ConfigurationManager.Conne ctionStrin gs["strDBC ourseStand ard"].Conn ectionStri ng;
con4.Open();
string strSQL = "Select Distinct * from ClassScheduleView where SchoolYear = 2010 and Course_Abb = 'AR202' and Semester = 'F2Y2010' and Syllabus = 'Created - Approved' and Campus_Name = 'Fort Bliss'";
SqlCommand objCommand = new SqlCommand(strSQL, con4);
SqlDataReader objReader = objCommand.ExecuteReader() ;
DataGrid1.VirtualItemCount = 10000;
DataGrid1.DataSource = objReader;
DataGrid1.DataBind();
objReader.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
work();
}
protected void DataGrid1_SelectedIndexCha nged(objec t sender, DataGridPageChangedEventAr gs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
work();
}
protected void GridPageIndexChanged(objec t sender, System.Web.UI.WebControls. DataGridPa geChangedE ventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
work();
}
}
--------------------------
Error 4 No overload for 'DataGrid1_SelectedIndexCh
--------------------------
aspx code
--------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RealDataGridDele
<!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>
<br />
<br />
<asp:DataGrid ID="DataGrid1" runat="server" AllowCustomPaging="True"
AllowPaging="True" PageSize="10" AllowSorting="True"
OnPageIndexChanged="GridPa
<PagerStyle Mode="NumericPages" HorizontalAlign="Right" />
</asp:DataGrid>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
<p>
</p>
</body>
</html>
--------------------------
cs code
--------------------------
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.UI.WebControls.
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
public partial class RealDataGridDeleteMe3YouBe
{
protected void Page_Load(object sender, EventArgs e)
{ }
public void work()
{
System.Data.SqlClient.SqlC
con4.ConnectionString = ConfigurationManager.Conne
con4.Open();
string strSQL = "Select Distinct * from ClassScheduleView where SchoolYear = 2010 and Course_Abb = 'AR202' and Semester = 'F2Y2010' and Syllabus = 'Created - Approved' and Campus_Name = 'Fort Bliss'";
SqlCommand objCommand = new SqlCommand(strSQL, con4);
SqlDataReader objReader = objCommand.ExecuteReader()
DataGrid1.VirtualItemCount
DataGrid1.DataSource = objReader;
DataGrid1.DataBind();
objReader.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
work();
}
protected void DataGrid1_SelectedIndexCha
{
DataGrid1.CurrentPageIndex
work();
}
protected void GridPageIndexChanged(objec
{
DataGrid1.CurrentPageIndex
work();
}
}
sorry.. my bad...
you can now delete:
protected void DataGrid1_SelectedIndexCha nged(objec t sender, DataGridPageChangedEventAr gs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
work();
}
and also remove this from the ASPX:
onselectedindexchanged="Da taGrid1_Se lectedInde xChanged"
you can now delete:
protected void DataGrid1_SelectedIndexCha
{
DataGrid1.CurrentPageIndex
work();
}
and also remove this from the ASPX:
onselectedindexchanged="Da
ASKER
Still not paging through the records after the changes project builds but still not working? Did I forget anything?
Does it stop in the GridPageIndexChanged method if you put a breakpoitn and try to page?
ASKER
No actually it will load watever page is selected from the bottom but will not load the information from that page. i.e. : on the list select page 6 and then it refreshes but the information that should be on page six is not displaying on the information on page one. I did add more code to see if that would help with the paging...
ASPX
____________
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RealDataGridDele teMe3YouBe tterFuckin gWork.aspx .cs" Inherits="RealDataGridDele teMe3YouBe tterFuckin gWork" %>
<!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>
<br />
<br />
<asp:DataGrid ID="DataGrid1" runat="server" AllowCustomPaging="True"
AllowPaging="True" PageSize="10" AllowSorting="True"
OnPageIndexChanged="GridPa geIndexCha nged" ShowFooter="True">
<PagerStyle Mode="NumericPages" HorizontalAlign="Right" />
</asp:DataGrid>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
CS
__________________________ __________ _____
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.UI.WebControls. Adapters;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls. WebParts;
public partial class RealDataGridDeleteMe3YouBe tterFuckin gWork : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
public void work()
{
System.Data.SqlClient.SqlC onnection con4 = new System.Data.SqlClient.SqlC onnection( );
con4.ConnectionString = ConfigurationManager.Conne ctionStrin gs["strDBC ourseStand ard"].Conn ectionStri ng;
con4.Open();
string strSQL = "Select Distinct * from ClassScheduleView where SchoolYear = 2010 and Course_Abb = 'AR202' and Semester = 'F2Y2010' and Syllabus = 'Created - Approved' and Campus_Name = 'Fort Bliss'";
SqlCommand objCommand = new SqlCommand(strSQL, con4);
SqlDataReader objReader = objCommand.ExecuteReader() ;
DataGrid1.VirtualItemCount = 10000;
DataGrid1.DataSource = objReader;
Session["PageSize"] = 25;
Session["PageStart"] = 0;
DataGrid1.DataBind();
objReader.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
work();
}
protected void GridPageIndexChanged(objec t sender, DataGridPageChangedEventAr gs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
work();
}
}
__________________________ ______
No I was trying to use intCounter but it keptblowing up in my face. ....
ASPX
____________
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RealDataGridDele
<!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>
<br />
<br />
<asp:DataGrid ID="DataGrid1" runat="server" AllowCustomPaging="True"
AllowPaging="True" PageSize="10" AllowSorting="True"
OnPageIndexChanged="GridPa
<PagerStyle Mode="NumericPages" HorizontalAlign="Right" />
</asp:DataGrid>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
CS
__________________________
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.UI.WebControls.
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
public partial class RealDataGridDeleteMe3YouBe
{
protected void Page_Load(object sender, EventArgs e)
{ }
public void work()
{
System.Data.SqlClient.SqlC
con4.ConnectionString = ConfigurationManager.Conne
con4.Open();
string strSQL = "Select Distinct * from ClassScheduleView where SchoolYear = 2010 and Course_Abb = 'AR202' and Semester = 'F2Y2010' and Syllabus = 'Created - Approved' and Campus_Name = 'Fort Bliss'";
SqlCommand objCommand = new SqlCommand(strSQL, con4);
SqlDataReader objReader = objCommand.ExecuteReader()
DataGrid1.VirtualItemCount
DataGrid1.DataSource = objReader;
Session["PageSize"] = 25;
Session["PageStart"] = 0;
DataGrid1.DataBind();
objReader.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
work();
}
protected void GridPageIndexChanged(objec
{
DataGrid1.CurrentPageIndex
work();
}
}
__________________________
No I was trying to use intCounter but it keptblowing up in my face. ....
put breakpoint on this line and let's see if it works.. DataGrid1.CurrentPageIndex = e.NewPageIndex;
ASKER
It hits the breakpoint and states
DataGrid1.CurrentPageIndex {DataGrid1.CurrentPageInde x 0}
= e.NewPageIndex; {e.NewPageIndex 5}
I can screen share with you if you like.
DataGrid1.CurrentPageIndex
= e.NewPageIndex; {e.NewPageIndex 5}
I can screen share with you if you like.
yes.. do that let's see...
ASKER
ASKER
hope you got that still awaiting a reply
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
MlandaT IS A CODE GOD!!!
For those of you intrested
HERE IS THE FINAL CODE AND WALK THROUGH
ASPX
______________
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RealDataGridDele teMe3YouBe tterFuckin gWork.aspx .cs" Inherits="RealDataGridDele teMe3YouBe tterFuckin gWork" %>
<!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>
<br />
<br />
<asp:DataGrid ID="DataGrid1" runat="server" AllowCustomPaging="False"
AllowPaging="True" PageSize="10" AllowSorting="True"
OnPageIndexChanged="GridPa geIndexCha nged" ShowFooter="True">
<PagerStyle Mode="NumericPages" HorizontalAlign="Right" />
</asp:DataGrid>
<br />
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
____________
aspx.cs
_______________
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.UI.WebControls. Adapters;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls. WebParts;
public partial class RealDataGridDeleteMe3YouBe tterFuckin gWork : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
public void work()
{
System.Data.SqlClient.SqlC onnection con4 = new System.Data.SqlClient.SqlC onnection( );
con4.ConnectionString = ConfigurationManager.Conne ctionStrin gs["strDBC ourseStand ard"].Conn ectionStri ng;
con4.Open();
string strSQL = "Select Distinct * from ClassScheduleView where SchoolYear = 2010 and Course_Abb = 'AR202' and Semester = 'F2Y2010' and Syllabus = 'Created - Approved' and Campus_Name = 'Fort Bliss'";
SqlCommand objCommand = new SqlCommand(strSQL, con4);
SqlDataAdapter da = new SqlDataAdapter("Select Distinct * from ClassScheduleView where SchoolYear = 2010 and Course_Abb = 'AR202' and Semester = 'F2Y2010' and Syllabus = 'Created - Approved' and Campus_Name = 'Fort Bliss'", con4);
System.Data.DataSet ds = new System.Data.DataSet();
da.Fill(ds);
DataGrid1.DataSource = ds.Tables[0];
DataGrid1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
work();
}
protected void GridPageIndexChanged(objec t sender, DataGridPageChangedEventAr gs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
work();
}
}
For those of you intrested
HERE IS THE FINAL CODE AND WALK THROUGH
ASPX
______________
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RealDataGridDele
<!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>
<br />
<br />
<asp:DataGrid ID="DataGrid1" runat="server" AllowCustomPaging="False"
AllowPaging="True" PageSize="10" AllowSorting="True"
OnPageIndexChanged="GridPa
<PagerStyle Mode="NumericPages" HorizontalAlign="Right" />
</asp:DataGrid>
<br />
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
____________
aspx.cs
_______________
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.UI.WebControls.
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
public partial class RealDataGridDeleteMe3YouBe
{
protected void Page_Load(object sender, EventArgs e)
{ }
public void work()
{
System.Data.SqlClient.SqlC
con4.ConnectionString = ConfigurationManager.Conne
con4.Open();
string strSQL = "Select Distinct * from ClassScheduleView where SchoolYear = 2010 and Course_Abb = 'AR202' and Semester = 'F2Y2010' and Syllabus = 'Created - Approved' and Campus_Name = 'Fort Bliss'";
SqlCommand objCommand = new SqlCommand(strSQL, con4);
SqlDataAdapter da = new SqlDataAdapter("Select Distinct * from ClassScheduleView where SchoolYear = 2010 and Course_Abb = 'AR202' and Semester = 'F2Y2010' and Syllabus = 'Created - Approved' and Campus_Name = 'Fort Bliss'", con4);
System.Data.DataSet ds = new System.Data.DataSet();
da.Fill(ds);
DataGrid1.DataSource = ds.Tables[0];
DataGrid1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
work();
}
protected void GridPageIndexChanged(objec
{
DataGrid1.CurrentPageIndex
work();
}
}
ASKER
CODE GOD!!!!!! LISTEN TO HIM!!!!!
HawaiiDragon! Looooooll..... thanks...... hahahaha.... best laugh I've had today!
DataGrid1.CurrentPageIndex
'Bind the DataGrid again with the Data Source
DataGrid1.DataSource = dataSet1
DataGrid1.DataBind()
End Sub
and in the ASPX:
AllowSorting="True" ShowFooter="True" AllowCustomPaging="True" OnPageIndexChanged="GridPa