DataGrid Paging

G

Guest

Hi I really can't figure out what's wrong with my code

<asp:datagrid id="DataGrid1" runat="server"
AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="True"
OnPageIndexChanged="ChangeIndex">
<PagerStyle Mode="NumericPages"></PagerStyle>
....

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
this.sqlConnection1 = new SqlConnection (DBConstant.connectionDB);
this.sqlConnection1.Open ();
HttpCookie cookie = Request.Cookies["hopitalID"];
strCookieValue = cookie.Value.ToString(); fillData ();
DataGrid1.CurrentPageIndex = 1;
}
}

private void fillData ()
{
string sql = "SELECT DISTINCT FACTURE.ID_NR_FACTURE, " +
"ANALYSE.ID_ANALYSE, FACTURE.DATE_FACTURE " +
"AS DATE_FACTURE, PATIENT.PRENOM_PATIENT, " +
"PATIENT.NOM_PATIENT ,FACTURE.FACTURE, " +
"FACTURE.ACQUITTE FROM PATIENT, LABORATOIRE, " +
"ANALYSE, FACTURE WHERE ANALYSE.ID_ANALYSE = " +
"FACTURE.ID_ANALYSE AND ANALYSE.ID_PATIENT = " +
"PATIENT.ID_PATIENT AND ANALYSE.LABO_ID = " +
"LABORATOIRE.ID_LABORATOIRE AND " +
"LABORATOIRE.DESIGNATION_LABORATOIRE = '" +
strCookieValue + "'" ;
DataSet ds = new DataSet ();
SqlDataAdapter adapter = new SqlDataAdapter (sql, this.sqlConnection1);
adapter.Fill (ds);
this.DataGrid1.DataSource = ds;
this.DataGrid1.DataBind();
}

protected void ChangeIndex(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
fillData ();
}

really thanks in advance
 
G

Guest

Dear Alexandre,

Change your Paging method's access level to public, as follows:-

public void ChangeIndex(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
fillData ();
}

That should solve your problem.

Thanks.
 
G

Guest

Thanks for your response but it's still doesn't work, I just open a book
about asp.net and they purpose another solution but still doesn't work ...

If someone have a working sample it's would be great

ranganh said:
Dear Alexandre,

Change your Paging method's access level to public, as follows:-

public void ChangeIndex(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
fillData ();
}

That should solve your problem.

Thanks.





Alexandre Jaquet said:
Hi I really can't figure out what's wrong with my code

<asp:datagrid id="DataGrid1" runat="server"
AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="True"
OnPageIndexChanged="ChangeIndex">
<PagerStyle Mode="NumericPages"></PagerStyle>
...

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
this.sqlConnection1 = new SqlConnection (DBConstant.connectionDB);
this.sqlConnection1.Open ();
HttpCookie cookie = Request.Cookies["hopitalID"];
strCookieValue = cookie.Value.ToString(); fillData ();
DataGrid1.CurrentPageIndex = 1;
}
}

private void fillData ()
{
string sql = "SELECT DISTINCT FACTURE.ID_NR_FACTURE, " +
"ANALYSE.ID_ANALYSE, FACTURE.DATE_FACTURE " +
"AS DATE_FACTURE, PATIENT.PRENOM_PATIENT, " +
"PATIENT.NOM_PATIENT ,FACTURE.FACTURE, " +
"FACTURE.ACQUITTE FROM PATIENT, LABORATOIRE, " +
"ANALYSE, FACTURE WHERE ANALYSE.ID_ANALYSE = " +
"FACTURE.ID_ANALYSE AND ANALYSE.ID_PATIENT = " +
"PATIENT.ID_PATIENT AND ANALYSE.LABO_ID = " +
"LABORATOIRE.ID_LABORATOIRE AND " +
"LABORATOIRE.DESIGNATION_LABORATOIRE = '" +
strCookieValue + "'" ;
DataSet ds = new DataSet ();
SqlDataAdapter adapter = new SqlDataAdapter (sql, this.sqlConnection1);
adapter.Fill (ds);
this.DataGrid1.DataSource = ds;
this.DataGrid1.DataBind();
}

protected void ChangeIndex(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
fillData ();
}

really thanks in advance
 

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

Similar Threads


Top