For that you have to use linkbuton in the footer and in rowdatabound you have to bind pageindex with that link button.
Then while handling the link button click event in the rowcommand event you have to check the button text and move page as per your current page index.
Its working good what i expected, but there is als0 some problem.
because i have display a question papers with choices(Radiobuttons) If the first page of gridview is displaying 5 questions
user checked 5 radiobuttons in that, then they click "Next" it again call the page _Load event. so i wrote the gridbinding concept within
!IsPOstback. Now if i click the "Next" it goes to page_Load and not goes into !IsPostback so the grid not disply there.
If i remove !IsPostback I lost my checked values of radiobutton when it call the page_Load event again when click the "Next".
If i remove !IsPostback I lost my checked values of radiobutton when it call the page_Load event again when click the "Next".
Since the Radiobuttons are dynamically added to page, to maintain view state of dynamic controls across postbacks, try binding data to grid in Page_Init event.
ssjGanesh
Participant
1928 Points
1352 Posts
How to view next 5 rows from grid by click a link
Feb 20, 2012 08:24 AM|LINK
I have a gridview with pagination thats displays only 5 rows but it contains morethan 20 rows.
If i click 1,2,3,4 last option,it displays the corresponding records thats not a issue.
But If i click NextSet link it should show another 5 rows,If i click again the NextSet link it should show another 5 rows.
same as i need to view next 5 rows by clicking a link.
How to do?
Mark as answer,if it helped U!
dinesh kumar...
Participant
986 Points
247 Posts
Re: How to view next 5 rows from grid by click a link
Feb 20, 2012 08:32 AM|LINK
For that you have to use linkbuton in the footer and in rowdatabound you have to bind pageindex with that link button.
Then while handling the link button click event in the rowcommand event you have to check the button text and move page as per your current page index.
Jai Jagannath
ssjGanesh
Participant
1928 Points
1352 Posts
Re: How to view next 5 rows from grid by click a link
Feb 20, 2012 08:52 AM|LINK
How to add footer control?
If i add that it displays every page of that grid, consider this is the last page of that gridview means
the link also displying there,so user may try to hit that link again.
Mark as answer,if it helped U!
chowdary143
Member
22 Points
26 Posts
Re: How to view next 5 rows from grid by click a link
Feb 20, 2012 08:56 AM|LINK
just set page size property to 5
and use below code
karthicks
All-Star
31378 Points
5422 Posts
Re: How to view next 5 rows from grid by click a link
Feb 20, 2012 09:02 AM|LINK
<asp:GridView ID="GridView1" runat="server" PageSize="5" AllowPaging="true" OnRowCommand="GridView1_RowCommand"> <PagerTemplate> <asp:Button ID="btnNext" runat="server" Text="Next" CommandName="Next" /> <asp:Button ID="btnPrev" runat="server" Text="Prev" CommandName="Prev"/> </PagerTemplate> </asp:GridView> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { ViewState["PageIndex"] = 0; this.BindGrid(); } } private void BindGrid() { this.GridView1.DataSource = new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "O", "P", "Q", "R" }; this.GridView1.DataBind(); } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int index = Convert.ToInt16(ViewState["PageIndex"]); if (e.CommandName == "Next") this.GridView1.PageIndex = index + 1; else this.GridView1.PageIndex = index - 1; this.BindGrid(); ViewState["PageIndex"] = this.GridView1.PageIndex > 0 ? this.GridView1.PageIndex : 1; }Karthick S
ssjGanesh
Participant
1928 Points
1352 Posts
Re: How to view next 5 rows from grid by click a link
Feb 20, 2012 09:11 AM|LINK
Thanks,
actually i am preparing this for online exam. i need only next button .If i click that button it shows another set of results.
I should not enable the previous page to the user.
Mark as answer,if it helped U!
Zhongqing Ta...
Star
10512 Points
1354 Posts
Re: How to view next 5 rows from grid by click a link
Feb 22, 2012 07:31 AM|LINK
Hi,
You can customize the Pager Template. Try this
<asp:GridView ..... onrowcommand="GridView1_RowCommand"> <Columns> </Columns> <PagerTemplate> <asp:Button ID="btnNext" CommandName="Next" runat="server" Text="Next" /> </PagerTemplate> </asp:GridView>protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Next") { GridView1.PageIndex += 1; GridView1.DataBind(); } }If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
ssjGanesh
Participant
1928 Points
1352 Posts
Re: How to view next 5 rows from grid by click a link
Feb 22, 2012 09:34 AM|LINK
Hi thanks.,
Zhongqing Tang - MSFT
Its working good what i expected, but there is als0 some problem.
because i have display a question papers with choices(Radiobuttons) If the first page of gridview is displaying 5 questions
user checked 5 radiobuttons in that, then they click "Next" it again call the page _Load event. so i wrote the gridbinding concept within !IsPOstback. Now if i click the "Next" it goes to page_Load and not goes into !IsPostback so the grid not disply there.
If i remove !IsPostback I lost my checked values of radiobutton when it call the page_Load event again when click the "Next".
Mark as answer,if it helped U!
Vijay Giggs
Member
160 Points
55 Posts
Re: How to view next 5 rows from grid by click a link
Feb 22, 2012 11:50 AM|LINK
Hi,
karthicks has provided the perfect example.
Your issue can be solved by using this example.
Zhongqing Ta...
Star
10512 Points
1354 Posts
Re: How to view next 5 rows from grid by click a link
Feb 23, 2012 04:43 AM|LINK
Hi,
Since the Radiobuttons are dynamically added to page, to maintain view state of dynamic controls across postbacks, try binding data to grid in Page_Init event.
protected void Page_Init(object sender, EventArgs e) { // // Try binding data here // } protected void Page_Load(object sender, EventArgs e) { }If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework