I am trying to create a gridview with an icon that when hovered over shows some more details. I have managed to get it to the point of showing the panel but it keeps showing the html that is loaded as the page is loaded.
Here is the html.
<%@ Page Title="HueniData" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="HueniData.aspx.cs" Inherits="Dateflowe.HueniData" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<br />
<div>
<asp:Label ID="lblToDate" runat="server" Text="To Date" Width="150px"></asp:Label>
<asp:Label ID="lblFromDate" runat="server" Text="From Date" Width="150px"></asp:Label><br />
<asp:TextBox ID="txtToDate" runat="server" type="date" Width="150px"></asp:TextBox>
<asp:TextBox ID="txtFromDate" runat="server" type="date" Width="150px"></asp:TextBox>
<asp:Label ID="txtIncorrectDateError" runat="server" Font-Bold="true" ForeColor="Red" Visible="false"></asp:Label><br />
<br />
<asp:Button ID="btnSelectDate" runat="server" Text="Select" OnClick="btnSelectDate_Click" />
<br />
</div>
<hr />
<div style="width: 1050px; height: 300px; overflow: auto; margin-left: 40px">
<asp:GridView ID="HueniGrid" runat="server" HeaderStyle-BackColor="Black" HeaderStyle-ForeColor="Silver" RowStyle-BackColor="#EEEEEE" AlternatingRowStyle-BackColor="White"
AlternatingRowStyle-ForeColor="#000" AutoGenerateColumns="false" AllowPaging="false" AllowSorting="true" Visible="false" OnRowCreated="HueniGrid_RowCreated">
<Columns>
<asp:BoundField DataField="LotNo" HeaderText="Lot No" />
<asp:BoundField DataField="Recipe" HeaderText="Recipe" />
<asp:BoundField DataField="PlantOrigin" HeaderText="Plant Origin" />
<asp:BoundField DataField="LoadWeight" HeaderText="Load Weight" />
<asp:BoundField DataField="StartTime" HeaderText="Start Time" />
<asp:BoundField DataField="StartedBy" HeaderText="Started By" />
<asp:BoundField DataField="BatchNo" HeaderText="Batch No" />
<asp:BoundField DataField="DrumNo" HeaderText="Drum No" />
<asp:BoundField DataField="TotalActualDuration" HeaderText="Total Actual Duration" />
<asp:BoundField DataField="TotalRecipeDuration" HeaderText="Total Recipe Duration" />
<%--Adding javascript field for pop up--%>
<asp:TemplateField ItemStyle-Width="40" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl="http://sheepsystems.com/bookmacster/HelpBook/images/InlineMagGlass.png" />
<ajax:PopupControlExtender ID="PopupControlExtender1" runat="server"
PopupControlID="Panel1"
TargetControlID="Image1"
DynamicContextKey='<%# Eval("BatchNo") %>'
DynamicControlID="Panel1"
DynamicServiceMethod="GetContent" Position="Bottom">
</ajax:PopupControlExtender>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Panel ID="Panel1" runat="server"></asp:Panel> <%--This is the popup--%>
</div>
</asp:Content>
and the relevant code:
protected void HueniGrid_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
PopupControlExtender pce = e.Row.FindControl("PopupControlExtender1") as PopupControlExtender;
string behaviourID = "pce_" + e.Row.RowIndex;
pce.BehaviorID = behaviourID;
Image img = (Image)e.Row.FindControl("Image1");
string OnMouseOverScript = string.Format("$find('{0}').showPopup();", behaviourID);
string OnMouseOutScript = string.Format("$find('{0}').hidePopup();", behaviourID);
img.Attributes.Add("onmouseover", OnMouseOverScript);
img.Attributes.Add("onmouseout", OnMouseOutScript);
}
}
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string GetDynamicContent(string contextKey) //static method
{
string connectionString = ConfigurationManager.ConnectionStrings["dataflowe_dbConnectionString"].ConnectionString;
string query = "SELECT TOP 1 OperationName FROM DrumProcess WHERE BatchNo = " + contextKey;
SqlDataAdapter da = new SqlDataAdapter(query, connectionString);
DataTable table = new DataTable();
da.Fill(table);
StringBuilder builder = new StringBuilder();
builder.Append("<table style='background-color:#f3f3f3; border: #336699 3px solid; ");
builder.Append("width: 350px; font-size:10pt; font-family:Verdana; ' cellspacing='0' cellpadding='3'>");
builder.Append("<tr><td colspan='3' style='background-color:#336699; color:white;'>");
builder.Append("<tr><td style='width:80px;'><b>OperationName</b></td>");
builder.Append("<tr>");
builder.Append("<td>" + table.Rows[0]["OperationName"].ToString() + "</td>");
builder.Append("</tr>");
builder.Append("</table>");
return builder.ToString();
}
What happens is it shows everything on the page as it first loads into the panel. From what I can personally see the problem is that it never calls the second method GetDynamicContent. It runs through the first method fine though. I have read this may to be to do with a web services file been called, rather than the method, which results in the page been reloaded? I have no clue about this. I added this:
DynamicServicePath="HueniData.aspx.cs"
When I do this the pop up no longer shows but neither does the data. Nothing shows.
When I use:
DynamicServicePath="HueniData.aspx"
I get an error message showing in the pop up panel which states: Web Service Call Failed: 200
I am completely lost and hope someone can help