You probably added a pager template to the gridview at some point and it is blank. You won't see the pager at all if it is blank regardless of the other settings. You have to delete your pager template to get it to go back to the built-in pager style.
oned_gk
All-Star
30979 Points
6338 Posts
Re: Pager not showing for GridView
Dec 02, 2012 04:33 PM|LINK
oned_gk
All-Star
30979 Points
6338 Posts
Re: Pager not showing for GridView
Dec 03, 2012 12:00 AM|LINK
Pass itemindex to button eventargument
<Columns> . . . <asp:TemplateField> <ItemTemplate> <asp:Button ID="Button1" runat="server" Text="Button" commandname="Button1Command" CommandArgument='<%# Container.DataItemIndex %>' /> </ItemTemplate> </asp:TemplateField> </Columns>if (e.CommandName=="Button1Command") { 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); }Sorry for changing code, no problem with your code.
Add if condition to your code to make sure only the button will execute the code. Without IF condition, your code will be executed by all rowcommands.
banksidepoet
Participant
774 Points
862 Posts
Re: Pager not showing for GridView
Dec 03, 2012 09:10 AM|LINK
Hi,
Thanks again for the response, and for sticking with this.
I have implemented your code as an ImageButton (as I would like to use an Image for the button), like so:
and here's the new code in CodeBehind:
protected void listProductsGridView_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "adToQuoteButtonCommand") { 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);I am NOW getting an error with a different piece of code:
protected void listProductsGridView_RowCreated(Object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ImageButton addButton = (ImageButton)(e.Row.Cells[5].Controls[0]); addButton.CommandArgument = e.Row.RowIndex.ToString();The error is:
Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.ImageButton'.
**********
Any ideas?
oned_gk
All-Star
30979 Points
6338 Posts
Re: Pager not showing for GridView
Dec 03, 2012 09:28 AM|LINK
banksidepoet
Participant
774 Points
862 Posts
Re: Pager not showing for GridView
Dec 03, 2012 09:57 AM|LINK
oned_gk.
I assume this code was to replace the same in "RowCommand"?
Doing so leaves me with the same error in RowCreated.
Ideas?
banksidepoet
Participant
774 Points
862 Posts
Re: Pager not showing for GridView
Dec 03, 2012 10:05 AM|LINK
The error is here:
protected void listProductsGridView_RowCreated(Object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ImageButton addButton = (ImageButton)(e.Row.Cells[5].Controls[0]); addButton.CommandArgument = e.Row.RowIndex.ToString();I haven't changed this code at all since it worked well with the ButtonField code we have now changed into a TemplateField containing an ImageButton.
maximummike
Member
4 Points
2 Posts
Re: Pager not showing for GridView
Apr 02, 2013 06:23 PM|LINK
You probably added a pager template to the gridview at some point and it is blank. You won't see the pager at all if it is blank regardless of the other settings. You have to delete your pager template to get it to go back to the built-in pager style.