Problem of query's data of a GridView are invisible after using personal pagersettings

  • Thread starter Thread starter Rednuts72
  • Start date Start date
R

Rednuts72

Guest
Hello,

I want to build a personal pagination with the properties VirtualItemCount and AllowCustomPaging of a control GridView.

When I used the second query without the function of pagination, the data are showing in the GridView and when I used the first query with the personal pagination, the data arent showing.

The following code is :


<asp:GridView id="Grv12" runat="server" AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None" style="z-index: 1; left: 35px; top: 260px; ; height: auto; width: 783px" AutoGenerateColumns="False"
DataKeyNames="TP_Article_Designation,TP_Article_Famille"
OnPageIndexChanging="GrdView1_PageIndexChanging"
onrowcommand="GridView_RowCommand" PagerStyle-BorderStyle="Inset" PagerSettings-Position="TopAndBottom" PagerSettings-Mode="NextPrevious" ShowHeader="true" ShowFooter="True" AllowPaging="True" AllowCustomPaging="True" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="@Rownum:=@Rownum+1" HeaderText="Numéro" />
<asp:BoundField DataField="IdTp_Article" HeaderText="Code Art" SortExpression="IdTP_Article"/>
<asp:BoundField DataField="TP_Article_Designation" HeaderText="Désignation" SortExpression="TP_Article_Designation" />
<asp:BoundField Datafield="TP_Article_Famille" HeaderText="Famille" SortExpression="TP_Article_Famille" />
<asp:BoundField DataField="TP_Article_Unité" HeaderText="Unité" SortExpression="TP_Article_Unité" />
<asp:BoundField DataField="TP_Article_Toutes" ShowHeader="False" Visible="false" />
<asp:BoundField DataField="TP_Article_Prix" HeaderText="Prix" SortExpression="TP_Article_Prix" />
<asp:buttonfield ButtonType="Button" CommandName="Insert" headertext="Panier" Text="Panier" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" >
</Columns>

<PagerSettings Mode="NextPrevious" Position="TopAndBottom" NextPageImageUrl="~/Images/fleche20droite2.gif" FirstPageText="First" PageButtonCount="5" PreviousPageImageUrl="~/Images/flechegauche2.gif" LastPageText="Last"></PagerSettings>

<PagerStyle ForeColor="White" HorizontalAlign="Center" />




</asp:GridView>


protected void Bt2Click(object sender, EventArgs e)
{
L_FamilleR.Text = DpList1.SelectedValue;

if (L_FamilleR.Text == Toutes & TB_DesignationR.Text == DesignationVide)
{
Grv12.VirtualItemCount = GetTotalCount();
NombreLigneSint = Convert.ToInt16(DropDownList1.SelectedValue);
GetPageData12(0, NombreLigneSint);
}
else if (L_FamilleR.Text != Toutes & TB_DesignationR.Text == DesignationVide)
{
SqlDataSourceTestPro12.SelectParameters.Clear();

SqlDataSourceTestPro12.SelectParameters.Add("?FamilleR", L_FamilleR.Text);
SqlDataSourceTestPro12.SelectCommand = "SET @Rownum=0;SELECT @Rownum:=@Rownum+1, idTP_Article, TP_Article_Designation, TP_Article_Famille, TP_Article_Unité, TP_Article_Prix, REPLACE(TP_Article_Prix,.,,) FROM tp_article WHERE TP_Article_Famille= ?FamilleR";

Grv12.DataSource = SqlDataSourceTestPro12;
Grv12.DataBind();

SqlDataSourceTestPro12.Dispose();
L_FamilleR.Dispose();
}

private int GetTotalCount()
{
DataSourceSelectArguments args = new DataSourceSelectArguments();
SqlDataSourceTestPro12.SelectCommand = "SELECT COUNT(*) FROM tp_article";
DataView DtView1 = (DataView)SqlDataSourceTestPro12.Select(args);
DataTable DtTable1 = DtView1.ToTable();
TotalLignes.Text = DtTable1.Rows[0][0].ToString();
return Convert.ToInt16(DtTable1.Rows[0][0].ToString());
}
protected void GrdView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
Grv12.PageIndex = e.NewPageIndex;
GetPageData12(e.NewPageIndex, NombreLigneSint);
}

public void GetPageData12(int index11, int NombreLigneSint)
{

string index11S = Convert.ToString(index11);
string NombreLigneS = Convert.ToString(NombreLigneSint);
L_FamilleR.Text = DpList1.SelectedValue;
SqlDataSourceTestPro12.SelectParameters.Clear();

SqlDataSourceTestPro12.SelectParameters.Add("?FamilleP", L_FamilleR.Text);
SqlDataSourceTestPro12.SelectParameters.Add("?PageIndex", index11S);
SqlDataSourceTestPro12.SelectParameters.Add("?PageSize", NombreLigneS);
SqlDataSourceTestPro12.SelectCommand = "SET @Rownum=0;SELECT @Rownum:=@Rownum+1, idTP_Article, TP_Article_Designation, TP_Article_Famille, TP_Article_Unité, TP_Article_Toutes, TP_Article_Prix, REPLACE(TP_Article_Prix,.,,) FROM tp_article WHERE TP_Article_Toutes= ?FamilleP AND @Rownum BETWEEN (((CAST(?PageIndex AS SIGNED))*CAST(?PageSize AS SIGNED))+1) AND (((CAST(?PageIndex AS SIGNED))+1)*CAST(?PageSize AS SIGNED))";

Grv12.DataSource = SqlDataSourceTestPro12;
Grv12.DataBind();
SqlDataSourceTestPro12.Dispose();
L_FamilleR.Dispose();
}



Is anybody to have the solution ?

Thanks !

Continue reading...
 
Back
Top