I had 5 pages in their own web-site. These pages have now been moved
to another web-site. Everything is fine except that one of the pages,
which I had trouble with in the past (i.e. same problem), is now
partly broke. The paging no longer fully works in the gridview.
The gvAwarded_RowDa taBound code works to load the ddlPager with the
correct number of pages.
The lnkPagerBack, and lnkPager controls continue to work at
incrementing and decrementing the page count but the ddlPager,
DropDownList, does not even post back when I click it (i.e. in debug
mode it does not run the server event).
What have I done wrong!
PS: The PagerTemplate has now been AJAXified (but it doesn't work
without the AJAX anyhow!, so I can't see how AJAX could be an issue -
although, the new site has some AJAX and the old site (from which it
was moved) has none.).
I've put the relevant code below.
<form id="frmPensions " runat="server">
<asp:ScriptMana ger ID="ScriptManag er1" runat="server" />
<asp:GridView ID="gvAwarded" AllowPaging="tr ue" AllowSorting="t rue"
AutoGenerateCol umns="false"
PageSize="20" DataKeyNames="A ctivityID" Runat="server"
CssClass="Grid" CellSpacing="2" BorderWidth="0p x" CellPadding="4"
EmptyDataText=" Non available"
OnRowDataBound= "gvAwarded_RowD ataBound"
OnSorting="gvAw arded_Sorting">
<AlternatingRow Style CssClass="Alter natingRow" BackColor="#d8d eEE"
VerticalAlign=" Top" />
<HeaderStyle CssClass="GridH eader" BackColor="#666 699"
HorizontalAlign ="Left" Font-Bold="True" ForeColor="Whit e"
Height="17px" VerticalAlign=" Top" />
<RowStyle CssClass="GridR ow" BackColor="Whit e"
VerticalAlign=" Top" />
<PagerStyle ForeColor="Whit e" BackColor="#666 699" Font-Bold="True"
CssClass="GridP ager" />
<PagerTemplat e>
<asp:UpdatePane l ID="UpdatePanel 1" runat="server">
<ContentTemplat e>
<div id="PageRow">
<asp:label id="MessageLabe l" CssClass="lblPa geMessage"
forecolor="Whit e" Font-Bold="true"
text="Select a page:"
Runat="server" />
<asp:DropDownLi st id="ddlPager" AutoPostBack="t rue"
ForeColor="Whit e" BackColor="#666 699" Font-Bold="true"
OnSelectedIndex Changed="ddlPag er_SelectedInde xChanged"
Runat="server" /
<asp:LinkButt on ID="lnkPagerBac k" ForeColor="Whit e"
ToolTip="Previo us"
runat="server" OnClick="lnkPag erBack_Click"
CssClass="lblPa geArrow"< </asp:LinkButton& nbsp;
<asp:LinkButt on ID="lnkPager" ForeColor="Whit e" ToolTip="Next"
runat="server" OnClick="lnkPag er_Click" CssClass="lblPa geArrow">
</asp:LinkButton><asp:label id="CurrentPage Label"
forecolor="Whit e" Font-Bold="true" Width="30%"
CssClass="lblPa geCurrent"
Runat="server" />
<asp:HiddenFiel d ID="txtPageInde x" runat="server" />
</div>
</ContentTemplate >
</asp:UpdatePanel >
</PagerTemplate>
<Columns>
<asp:BoundFie ld DataField="Cons ultantName" HeaderText="Con sultant"
SortExpression= "ConsultantName ">
<ItemStyle Width="15%" CssClass="acol1 " />
</asp:BoundField>
<asp:BoundFie ld DataField="Mana gerName" HeaderText="Man ager"
SortExpression= "ManagerNam e">
<ItemStyle Width="15%" CssClass="acol2 " />
</asp:BoundField>
<asp:BoundFie ld DataField="Asse tClassList" HeaderText="Ass et Class"
SortExpression= "AssetClassList ">
<ItemStyle Width="15%" CssClass="acol3 " />
</asp:BoundField>
<asp:BoundFie ld DataField="Amou nt" HeaderText="Amo unt"
SortExpression= "Amount" DataFormatStrin g="{0:GBP ###,### m; n/a}"
HtmlEncode="Fal se">
<ItemStyle Width="7%" CssClass="acol4 " />
</asp:BoundField>
<asp:BoundFie ld DataField="Pens ionFundName" HeaderText="Inv estor"
SortExpression= "PensionFundNam e">
<ItemStyle Width="20%" CssClass="acol5 " />
</asp:BoundField>
<asp:BoundFie ld DataField="Styl e" HeaderText="Sty le"
SortExpression= "Style" >
<ItemStyle Width="8%" CssClass="acol6 " />
</asp:BoundField>
<asp:BoundFie ld DataField="Coun tryName" HeaderText="Cou ntry"
SortExpression= "CountryNam e">
<ItemStyle Width="8%" CssClass="acol7 " />
</asp:BoundField>
<asp:BoundFie ld DataField="Entr yDate" HeaderText="Ent ry Date"
SortExpression= "EntryDate" HtmlEncode="Fal se" DataFormatStrin g ="{0:dd
MMM yyyy}">
<ItemStyle Width="11%" CssClass="acol8 " />
<HeaderStyle CssClass="ahcol 8" />
</asp:BoundField>
</Columns>
</asp:GridView>
</form>
....
protected void ddlPager_Select edIndexChanged( object sender, EventArgs
e)
{
GridViewRow pagerRow = gvAwarded.Botto mPagerRow;
DropDownList pageList;
if (pagerRow != null)
{
pageList = (DropDownList)p agerRow.Cells[0].FindControl("d dlPager");
gvAwarded.PageI ndex = pageList.Select edIndex;
}
BindGridView();
}
protected void lnkPager_Click( object sender, EventArgs e)
{
gvAwarded.PageI ndex++;
BindGridView();
}
protected void lnkPagerBack_Cl ick(object sender, EventArgs e)
{
if(gvAwarded.Pa geIndex 0)
gvAwarded.PageI ndex--;
BindGridView();
}
protected void gvAwarded_RowDa taBound(object sender,
GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.Header)
{
foreach (TableCell tc in e.Row.Cells)
{
tc.Attributes.A dd("title", "Sort");
}
}
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
e.Row.Cells[5].Text =
PensionWatch.St yleCodeToWord(e .Row.Cells[5].Text);
}
if (e.Row.RowType == DataControlRowT ype.Pager)
{
DropDownList pageList =
(DropDownList)e .Row.Cells[0].FindControl("d dlPager");
Label pageLabel =
(Label)e.Row.Ce lls[0].FindControl("C urrentPageLabel ");
for (int i = 0; i < gvAwarded.PageC ount; i++)
{
int pageNumber = i + 1;
ListItem item = new ListItem(pageNu mber.ToString() );
if (i == gvAwarded.PageI ndex)
item.Selected = true;
pageList.Items. Add(item);
}
int currentPage = gvAwarded.PageI ndex + 1;
pageLabel.Text = "Page " + currentPage.ToS tring() + " of " +
gvAwarded.PageC ount.ToString() ;
}