TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
bani marc
NA
54
2.5k
pageindexchanging issue
Oct 7 2017 6:28 AM
Hi everybody.
I have a gridview with pagination which is displaying filtered data from sql server. I have also a button. When this one is clicked, it's displaying all the data from sql server. My problem is that when I want to click on page 2, only the filtered data are displaying and not the second page of the total data.
Here is my code aspx:
<asp:Button ID="btnTteLivraisons" CssClass="btn btn-success" runat="server" Text="Toutes les livraisons" OnClick="btnTteLivraisons_Click" Visible="False" />
<asp:GridView ID=
"GridView1"
runat=
"server"
CssClass=
"mydatagrid"
PagerStyle-CssClass=
"pager"
HeaderStyle-CssClass=
"header"
RowStyle-CssClass=
"rows"
AllowPaging=
"True"
OnPageIndexChanging=
"GridView1_PageIndexChanging"
OnSorting=
"GridView1_Sorting"
AutoGenerateColumns=
"False"
CellPadding=
"4"
ForeColor=
"#333333"
GridLines=
"None"
Width=
"100%"
>
<SelectedRowStyle BackColor=
"#C5BBAF"
/>
<AlternatingRowStyle BackColor=
"White"
/>
<HeaderStyle HorizontalAlign=
"center"
/>
<Columns>
<asp:BoundField DataField=
"Nom"
HeaderText=
"Nom"
ItemStyle-HorizontalAlign=
"center"
/>
<asp:BoundField DataField=
"Prenom"
HeaderText=
"Prénom"
ItemStyle-HorizontalAlign=
"center"
/>
<asp:BoundField DataField=
"CP"
HeaderText=
"Code Postal"
ItemStyle-HorizontalAlign=
"center"
/>
<asp:BoundField DataField=
"ville"
HeaderText=
"Ville"
ItemStyle-HorizontalAlign=
"center"
/>
<asp:BoundField DataField=
"Telephone"
HeaderText=
"Téléphone"
ItemStyle-HorizontalAlign=
"center"
/>
<asp:BoundField DataField=
"date_command2"
HeaderText=
"Date Commande"
DataFormatString=
"<%$AppSettings:FormatDateGrille%>"
ItemStyle-HorizontalAlign=
"center"
/>
<asp:BoundField DataField=
"heure_command"
HeaderText=
"Heure Commande"
ItemStyle-HorizontalAlign=
"center"
/>
<asp:BoundField DataField=
"montantCommande"
HeaderText=
"Montant de la Commande"
ItemStyle-HorizontalAlign=
"center"
/>
<asp:TemplateField HeaderText=
""
>
<ItemTemplate>
<asp:Button id=
"btnCommande"
runat=
"server"
Text=
"Détail Commande"
OnClick=
"btnCommande_Click"
CommandArgument=
'<%# Eval("ID") %>'
class
=
"btn btn-info"
/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=
""
>
<ItemTemplate>
<asp:Button id=
"btnEdit"
runat=
"server"
Text=
"Editer"
OnClick=
"Edit"
CommandArgument=
'<%# Eval("ID") %>'
class
=
"btn btn-primary"
/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=
""
>
<ItemTemplate>
<asp:Button ID=
"btnSupprimer"
runat=
"server"
Text=
"Supprimer"
OnClick=
"Delete"
CommandArgument=
'<%# Eval("ID") %>'
CssClass=
"btn btn-danger"
/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
my code behind :
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
BindInfoLivraison();
btnTteLivraisons.Visible =
true
;
}
}
public
static
DataTable ToDataTable<T>(List<T> items)
{
DataTable dataTable =
new
DataTable(
typeof
(T).Name);
//Get all the properties
PropertyInfo[] Props =
typeof
(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach
(PropertyInfo prop
in
Props)
{
//Setting column names as Property names
dataTable.Columns.Add(prop.Name);
}
foreach
(T item
in
items)
{
var values =
new
object
[Props.Length];
for
(
int
i = 0; i < Props.Length; i++)
{
//inserting property values to datatable rows
values[i] = Props[i].GetValue(item,
null
);
}
dataTable.Rows.Add(values);
}
//put a breakpoint here and check datatable
return
dataTable;
}
private
void
BindInfoLivraison()
{
using
(RestauDBEntities1 db =
new
RestauDBEntities1())
{
if
(db.InfoLivraison.Count() > 0)
{
DateTime today = Convert.ToDateTime(DateTime.Now.ToString(
"dd/MM/yyyy"
));
List<InfoLivraison> list = (from infoLiv
in
db.InfoLivraison where infoLiv.date_command2 == today select infoLiv).ToList();
DataTable dt = ToDataTable<InfoLivraison>(list);
ViewState[
"livraison"
] = dt;
GridView1.DataSource = dt;
GridView1.DataBind();
}
else
{
GridView1.DataSource =
null
;
GridView1.DataBind();
}
}
}
private
void
BindInfoLivraisonTotal()
{
DataTable dt =
new
DataTable();
using
(RestauDBEntities1 db =
new
RestauDBEntities1())
{
if
(db.InfoLivraison.Count() > 0)
{
//string today = DateTime.Now.ToString("d");
GridView1.DataSource = (from infoLiv
in
db.InfoLivraison select infoLiv).ToList();
GridView1.DataBind();
}
else
{
GridView1.DataSource =
null
;
GridView1.DataBind();
}
}
}
protected
void
GridView1_PageIndexChanging(
object
sender, GridViewPageEventArgs e)
{
if
(ViewState[
"livraison"
] !=
null
)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = ViewState[
"livraison"
];
GridView1.DataBind();
}
}
Reply
Answers (
1
)
Asp.net web form
crop and print particular section of browsed pdf file