Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

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

$
0
0

Hello,

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

When I used th 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 aren't 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 !

<asp:gridview allowcustompaging="True" allowpaging="True" allowsorting="True" autogeneratecolumns="False" cellpadding="4" datakeynames="TP_Article_Designation,TP_Article_Famille" forecolor="#333333" gridlines="None" id="Grv12" onpageindexchanging="GrdView1_PageIndexChanging" onrowcommand="GridView_RowCommand" pagersettings-mode="NextPrevious" pagersettings-position="TopAndBottom" pagerstyle-borderstyle="Inset" runat="server" showfooter="True" showheader="true" style="left:35px;top:260px;width:783px;height:auto;;z-index:1;"><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" headerstyle-horizontalalign="Center" headertext="Panier" itemstyle-horizontalalign="Center" text="Panier"></asp:buttonfield></asp:boundfield></asp:boundfield></asp:boundfield></asp:boundfield></asp:boundfield></asp:boundfield></asp:boundfield></columns></alternatingrowstyle></asp:gridview>


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>