DropDownList inside GridView won't fire any longer! aka - I moved a page to another web-site and now

M

mark4asp

I moved a page to another web-site and now it's broke!

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_RowDataBound 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:ScriptManager ID="ScriptManager1" runat="server" />

<asp:GridView ID="gvAwarded" AllowPaging="true" AllowSorting="true"
AutoGenerateColumns="false"
PageSize="20" DataKeyNames="ActivityID" Runat="server"
CssClass="Grid" CellSpacing="2" BorderWidth="0px" CellPadding="4"
EmptyDataText="Non available"
OnRowDataBound="gvAwarded_RowDataBound"
OnSorting="gvAwarded_Sorting">

<AlternatingRowStyle CssClass="AlternatingRow" BackColor="#d8deEE"
VerticalAlign="Top" />
<HeaderStyle CssClass="GridHeader" BackColor="#666699"
HorizontalAlign="Left" Font-Bold="True" ForeColor="White"
Height="17px" VerticalAlign="Top" />
<RowStyle CssClass="GridRow" BackColor="White"
VerticalAlign="Top" />
<PagerStyle ForeColor="White" BackColor="#666699" Font-Bold="True"
CssClass="GridPager" />

<PagerTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="PageRow">
<asp:label id="MessageLabel" CssClass="lblPageMessage"
forecolor="White" Font-Bold="true"
text="Select a page:"
Runat="server" />
<asp:DropDownList id="ddlPager" AutoPostBack="true"
ForeColor="White" BackColor="#666699" Font-Bold="true"
OnSelectedIndexChanged="ddlPager_SelectedIndexChanged"
Runat="server" /> &nbsp;
<asp:LinkButton ID="lnkPagerBack" ForeColor="White"
ToolTip="Previous"
runat="server" OnClick="lnkPagerBack_Click"
CssClass="lblPageArrow"> < </asp:LinkButton> &nbsp;
<asp:LinkButton ID="lnkPager" ForeColor="White" ToolTip="Next"
runat="server" OnClick="lnkPager_Click" CssClass="lblPageArrow">
</asp:LinkButton>
<asp:label id="CurrentPageLabel"
forecolor="White" Font-Bold="true" Width="30%"
CssClass="lblPageCurrent"
Runat="server" />
<asp:HiddenField ID="txtPageIndex" runat="server" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</PagerTemplate>

<Columns>
<asp:BoundField DataField="ConsultantName" HeaderText="Consultant"
SortExpression="ConsultantName">
<ItemStyle Width="15%" CssClass="acol1" />
</asp:BoundField>
<asp:BoundField DataField="ManagerName" HeaderText="Manager"
SortExpression="ManagerName">
<ItemStyle Width="15%" CssClass="acol2" />
</asp:BoundField>
<asp:BoundField DataField="AssetClassList" HeaderText="Asset Class"
SortExpression="AssetClassList">
<ItemStyle Width="15%" CssClass="acol3" />
</asp:BoundField>
<asp:BoundField DataField="Amount" HeaderText="Amount"
SortExpression="Amount" DataFormatString="{0:GBP ###,### m; n/a}"
HtmlEncode="False">
<ItemStyle Width="7%" CssClass="acol4" />
</asp:BoundField>
<asp:BoundField DataField="PensionFundName" HeaderText="Investor"
SortExpression="PensionFundName">
<ItemStyle Width="20%" CssClass="acol5" />
</asp:BoundField>
<asp:BoundField DataField="Style" HeaderText="Style"
SortExpression="Style" >
<ItemStyle Width="8%" CssClass="acol6" />
</asp:BoundField>
<asp:BoundField DataField="CountryName" HeaderText="Country"
SortExpression="CountryName">
<ItemStyle Width="8%" CssClass="acol7" />
</asp:BoundField>
<asp:BoundField DataField="EntryDate" HeaderText="Entry Date"
SortExpression="EntryDate" HtmlEncode="False" DataFormatString ="{0:dd
MMM yyyy}">
<ItemStyle Width="11%" CssClass="acol8" />
<HeaderStyle CssClass="ahcol8" />
</asp:BoundField>
</Columns>
</asp:GridView>
</form>


....


protected void ddlPager_SelectedIndexChanged(object sender, EventArgs
e)
{
GridViewRow pagerRow = gvAwarded.BottomPagerRow;
DropDownList pageList;
if (pagerRow != null)
{
pageList = (DropDownList)pagerRow.Cells[0].FindControl("ddlPager");
gvAwarded.PageIndex = pageList.SelectedIndex;
}
BindGridView();
}
protected void lnkPager_Click(object sender, EventArgs e)
{
gvAwarded.PageIndex++;
BindGridView();
}
protected void lnkPagerBack_Click(object sender, EventArgs e)
{
if(gvAwarded.PageIndex > 0)
gvAwarded.PageIndex--;
BindGridView();
}

protected void gvAwarded_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
foreach (TableCell tc in e.Row.Cells)
{
tc.Attributes.Add("title", "Sort");
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[5].Text =
PensionWatch.StyleCodeToWord(e.Row.Cells[5].Text);
}
if (e.Row.RowType == DataControlRowType.Pager)
{
DropDownList pageList =
(DropDownList)e.Row.Cells[0].FindControl("ddlPager");
Label pageLabel =
(Label)e.Row.Cells[0].FindControl("CurrentPageLabel");

for (int i = 0; i < gvAwarded.PageCount; i++)
{
int pageNumber = i + 1;
ListItem item = new ListItem(pageNumber.ToString());
if (i == gvAwarded.PageIndex)
item.Selected = true;
pageList.Items.Add(item);
}
int currentPage = gvAwarded.PageIndex + 1;
pageLabel.Text = "Page " + currentPage.ToString() + " of " +
gvAwarded.PageCount.ToString();
}
 
M

mark4asp

Apologies for the post. I have fixed it now. The problem was that I
added two lines to Page_Load() (shown below, commented out). That was
because the page was sometimes loading with no data in the GridView!,
I guess I need to deal with that some other way. The AJAX is no good
either the entire GridView needs to be AJAXified or none of it.


protected void Page_Load(object sender, EventArgs e)
{
cmdMandatewire.Attributes.Add("onmouseover",
"MenuButtonIn(this);");
cmdMandatewire.Attributes.Add("onmouseout",
"MenuButtonOut(this);");
if (!Page.IsPostBack)
{
LoadData();
Session["SortExpression"] = "EntryDate";
Session["SortDirection"] = "DESC";
}
//else
// BindGridView();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top