If I take your Gridview , use my DataSource and all default events, I get the pagers on the header and footer. So, its nothing obvious. That leads me to believe it's either in the CSS or the OnRowDataBound or OnRowCreated events. I'd check CSS.
It doesn't seem to matter whether this line is commented out or not... on page load the GridView displays properly including Pager. The number of pages available from the Pager is right but, when I click on a Pager Number representing ANY other page than
the one I'm on, I get the same error posted above. Upon debugging, the value of "e.CommandArgument" is "2" (the number of the page I tried to navigate to). I have 15 products and PageSize set to "2" (number 1 to 8 in the pager - correct). It seems to be the
pager causing the error, not the RowCommand.
What is interesting is that the code in the RowCommand handler is intended to fire only when the button in each row is clicked. Is this some kind of ValidationGroup issue: changing the page via the pager is resulting in the effect of the button in each row
being clicked? Even if this was the case, why can't it get the value of the first column?
try set btn commandname="abc" and CommandArgument='<%# Container.DataItemIndex %>' . In rowcommand event use if : if (e.commandname=="abc") ... Int idx=e.commandargument ...
Again, forgive my ignorance but what do you mean by [idx]?
My current line is:
[int.Parse(e.CommandArgument.ToString())]
Are you asking me to replace this with something?
Also, CommandArgument is not allowed in a ButtonField. What can I do about this?
The ButtonField works perfectly well with my existing code (in that the id in column one is grabbed successfully at each button click. The error here is only present upon changing pages using the Pager.
banksidepoet
Participant
774 Points
862 Posts
Pager not showing for GridView
Dec 01, 2012 07:13 PM|LINK
Hi,
I have the following GridView code:
There are 15 rows in the unpaged GridView.
The Pager doesnt show on the GridView, top OR bottom.
Have I made an obvious error here?
paindaasp
Star
12070 Points
2034 Posts
Re: Pager not showing for GridView
Dec 01, 2012 08:23 PM|LINK
If I take your Gridview , use my DataSource and all default events, I get the pagers on the header and footer. So, its nothing obvious. That leads me to believe it's either in the CSS or the OnRowDataBound or OnRowCreated events. I'd check CSS.
oned_gk
All-Star
31407 Points
6419 Posts
Re: Pager not showing for GridView
Dec 01, 2012 11:58 PM|LINK
I am not sure what the problem. How many rows displayed in GV? Maybe you can do some test
In databound event try set label text
Try also to reset pagersetting to default by removing
You can also check how many rows your GV datasource
banksidepoet
Participant
774 Points
862 Posts
Re: Pager not showing for GridView
Dec 02, 2012 02:54 PM|LINK
paindaasp
Thanks for the response.
You were right: not CSS but this code:
protected void listProductsGridView_RowDataBound(object sender, GridViewRowEventArgs e) { // e.Row.Cells[0].Visible = false; }It's commented out here, and doing this made the pager appear.
The reason I have this line at all is explained best in one of my earlier posts:
http://forums.asp.net/t/1860395.aspx/1?Hiding+an+ID+column+in+a+GridView
You can see from my last post in this short thread what I did and why.
BUT your solution causes me two problems:
protected void listProductsGridView_RowCommand(object sender, GridViewCommandEventArgs e) { GridViewRow row = ((System.Web.UI.WebControls.GridView)(sender)).Rows[int.Parse(e.CommandArgument.ToString())]; string idString = row.Cells[0].Text; int id = Convert.ToInt32(idString);The error is: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
and the highlighted (red) row in the error page is "GridView row = ..." but I guess the error is the next line.
However, it IS the first column I'm after, which WOULD be index 0, yes?
Here's the MarkUp for that column:
Any ideas with either of these two extra problems?
Thanks
oned_gk
All-Star
31407 Points
6419 Posts
Re: Pager not showing for GridView
Dec 02, 2012 03:04 PM|LINK
banksidepoet
Participant
774 Points
862 Posts
Re: Pager not showing for GridView
Dec 02, 2012 03:18 PM|LINK
oned_gk.
Thamnks for the reposnse.
I have implemented your suggestion.
protected void listProductsGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[0].Visible = false; } }It doesn't seem to matter whether this line is commented out or not... on page load the GridView displays properly including Pager. The number of pages available from the Pager is right but, when I click on a Pager Number representing ANY other page than the one I'm on, I get the same error posted above. Upon debugging, the value of "e.CommandArgument" is "2" (the number of the page I tried to navigate to). I have 15 products and PageSize set to "2" (number 1 to 8 in the pager - correct). It seems to be the pager causing the error, not the RowCommand.
What is interesting is that the code in the RowCommand handler is intended to fire only when the button in each row is clicked. Is this some kind of ValidationGroup issue: changing the page via the pager is resulting in the effect of the button in each row being clicked? Even if this was the case, why can't it get the value of the first column?
If you have any ideas, I'd appreciate those.
Also, I'm desperately in need of urgent help with this: http://forums.asp.net/t/1862740.aspx/1?Urgent+help+needed+with+RowCommand+of+GridView as it's another RowCommand issue and you seem to know what you're talking about with this stuff.
Thanks.
oned_gk
All-Star
31407 Points
6419 Posts
Re: Pager not showing for GridView
Dec 02, 2012 03:37 PM|LINK
banksidepoet
Participant
774 Points
862 Posts
Re: Pager not showing for GridView
Dec 02, 2012 03:38 PM|LINK
oned_gk,
Apologies, can you expand on that a little? Bit above my head.
Can't set CommandArgument on a ButtonField.
oned_gk
All-Star
31407 Points
6419 Posts
Re: Pager not showing for GridView
Dec 02, 2012 03:51 PM|LINK
banksidepoet
Participant
774 Points
862 Posts
Re: Pager not showing for GridView
Dec 02, 2012 04:05 PM|LINK
oned_gk,
Again, forgive my ignorance but what do you mean by [idx]?
My current line is:
Are you asking me to replace this with something?
Also, CommandArgument is not allowed in a ButtonField. What can I do about this?
The ButtonField works perfectly well with my existing code (in that the id in column one is grabbed successfully at each button click. The error here is only present upon changing pages using the Pager.