This code works until I start flipping pages and or sorting the data by column.
It's an ASP gridview wrapped around in an ASP update panel with triggers. The user is supposed to hover over a
row with his or her mouse cursor and then an address displays. To do this I use an AJAX PopupControlExtender
that dynamically fills the content inside of an ASP panel; that ASP panel appears as the user hovers over a row
in the grid. It works fine without the update panel but I want to use the update panel.
Comments and suggestions please.
My ASP code:
<asp:UpdatePanel ID="updSrchRes" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gdvSrchRes" EventName="Sorting" />
<asp:AsyncPostBackTrigger ControlID="gdvSrchRes" EventName="PageIndexChanging" />
<asp:AsyncPostBackTrigger ControlID="gdvSrchRes" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="gdvSrchRes" EventName="SelectedIndexChanging" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="gdvSrchRes" runat="server" OnRowDataBound="gdvSrchRes_OnRowDataBound"
Width="100%" AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true"
GridLines="None" BorderStyle="None" OnPageIndexChanging="gdvSrchRes_OnPageIndexChanging"
PagerSettings-Position="Top" OnSorting="gdvSrchRes_Sorting" OnSelectedIndexChanging="gdvSrchRes_SelectedIndexChanging">
<RowStyle BackColor="#F8F5F5" />
<AlternatingRowStyle BackColor="Beige" />
<PagerStyle HorizontalAlign="Right" ForeColor="Red" />
<Columns>
<asp:BoundField HeaderText="Reference Number" DataField="HDR_ref_nbr" SortExpression="HDR_ref_nbr">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="First Name" DataField="APPL_fname" SortExpression="APPL_fname">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField HeaderText="Last Name" DataField="APPL_lname" SortExpression="APPL_lname">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField HeaderText="Policy Number" DataField="HDR_policy_nbr" SortExpression="HDR_policy_nbr"
ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="center" />
<asp:BoundField HeaderText="Effective Date" DataField="HDR_pol_eff_date" SortExpression="HDR_pol_eff_date"
DataFormatString="{0:MM/dd/yyyy}" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="center" />
<asp:BoundField HeaderText="User ID" DataField="HDR_tran_user_name" SortExpression="HDR_tran_user_name"
ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="center" />
<asp:BoundField HeaderText="Producer" DataField="USER_NameFull" SortExpression="USER_NameFull"
ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="center" />
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="imgLetter" runat="server" ImageUrl="~/Images/envelope.gif" />
<ajaxToolkit:PopupControlExtender ID="popCtrlExtAddPopUp" runat="server" DynamicServiceMethod="GetDynamicContent"
DynamicContextKey='<%# Eval("APPL_mail_addr") %>' DynamicControlID="pnlAddPopUP"
TargetControlID="imgLetter" PopupControlID="pnlAddPopUP" Position="right">
</ajaxToolkit:PopupControlExtender>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Panel ID="pnlAddPopUP" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
The C# Code:
protected void gdvSrchRes_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
PopupControlExtender addPopUp = e.Row.FindControl("popCtrlExtAddPopUp") as PopupControlExtender;
string behaviorID = string.Format("addPopUp{0}", e.Row.RowIndex);
addPopUp.BehaviorID = behaviorID;
string mouseOver = string.Format("$find('{0}').showPopup();{1}", behaviorID,
"this.style.cursor='hand';this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='Lime'");
string mouseout = string.Format("$find('{0}').hidePopup();{1}", behaviorID,
"this.style.backgroundColor=this.originalstyle;");
e.Row.Attributes.Add("onmouseover", mouseOver);
e.Row.Attributes.Add("onmouseout", mouseout);
e.Row.Attributes.Add("onClick", ClientScript.GetPostBackClientHyperlink(this.gdvSrchRes, "Select$" + e.Row.RowIndex));
}
}
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string GetDynamicContent(string contextKey)
{
StringBuilder htmlBuilder = new StringBuilder();
htmlBuilder.Append("<div>");
htmlBuilder.Append(string.Format("<h3>{0}</h3>", contextKey));
htmlBuilder.Append("</div>");
return htmlBuilder.ToString();
}