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
Ganesh babu
NA
40
3.1k
Grid view sorting and paging after performing search
Apr 18 2019 4:26 AM
I am performing a search operation in GridView and getting results as expected, but after getting results, if I sort them or click on pagination, the page getting reloaded and sorting and pagination happening for the whole grid. I want sorting and paging should only work for search results which I have got.
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
bindgrid();
}
}
protected
void
bindgrid()
{
ViewState[
"sortexp"
] =
""
;
ViewState[
"orderby"
] =
"ASC"
;
Sort(
""
);
int
iTotalRecords = ((DataTable)(GridView1.DataSource)).Rows.Count;
lbldisplay.Text =
"Total Products: "
+ iTotalRecords.ToString();
}
protected
void
GridView1_PageIndexChanging(
object
sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
bindgrid();
}
public
void
Sort(
string
sortexp)
{
DataTable dt = (DataTable)bll.LoadProduct();
DataView DV = dt.DefaultView;
if
(sortexp !=
""
)
{
DV.Sort = sortexp;
}
GridView1.DataSource = DV;
GridView1.DataBind();
}
protected
void
GridView1_Sorting(
object
sender, GridViewSortEventArgs e)
{
if
(ViewState[
"orderby"
].ToString() ==
"ASC"
)
{
ViewState[
"orderby"
] =
"DESC"
;
ViewState[
"sortexp"
] = e.SortExpression +
" "
+
" DESC"
;
}
else
{
ViewState[
"orderby"
] =
"ASC"
;
ViewState[
"sortexp"
] = e.SortExpression +
" "
+
" ASC"
;
}
Sort(ViewState[
"sortexp"
].ToString());
}
Reply
Answers (
5
)
Two Factor Authentication.
cant display fb name on mvc after login with facebook succe