我正在尝试创建一个带有图标的网格视图,当悬停在该图标上时会显示更多详细信息。我已经设法让它显示面板,但它一直显示在页面加载时加载的 html。
这是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>
和相关代码:
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();
}
发生的情况是它在第一次加载到面板时显示页面上的所有内容。从我个人看到的问题是它从不调用第二种方法GetDynamicContent。不过,它很好地贯穿了第一种方法。我读过这可能与调用 Web 服务文件有关,而不是方法导致页面被重新加载?我对此一无所知。我添加了这个:
DynamicServicePath="HueniData.aspx.cs"
当我这样做时,弹出窗口不再显示,但数据也没有。什么都没有显示。
当我使用:
DynamicServicePath="HueniData.aspx"
我在弹出面板中收到一条错误消息,指出:Web Service Call Failed: 200
我完全迷路了,希望有人能提供帮助