gpt4 book ai didi

c# - 如何使用 PopupControlExtender 弹出 ASP.NET 控件而不是面板?

转载 作者:太空宇宙 更新时间:2023-11-03 15:44:53 24 4
gpt4 key购买 nike

PopupControlExtender 可以弹出许多ASP.NET 控件,但是在Internet 上只能找到弹出面板 的示例...如何弹出gridview等其他控件?

例如我将通过 MachineNo 从数据库中获取一个 DataTable,并将 DataTable 设置为 GridView2 的数据源。然后我想弹出 GridView2,当鼠标悬停在图像按钮上时显示该机器的信息。后面的代码怎么写?

<asp:GridView ID="GridView1" ...onrowcreated="GridView1_RowCreated">
<Columns>
<asp:BoundField HeaderText="MachineNo" DataField="MachineNo"/>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" .../>
<cc1:PopupControlExtender ID="PopupControlExtender1" runat="server"
PopupControlID="GridView2"
TargetControlID="ImageButtonl"
DynamicContextKey='<%# Eval("MachineNo") %>'
DynamicControlID="GridView2"
DynamicServiceMethod="GetDynamicContent" ???>
</cc1:PopupControlExtender>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<asp:GridView ID="GridView2" ...>...

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e){
if (e.Row.RowType == DataControlRowType.DataRow)
{
PopupControlExtender PopupControlExtender1 = (PopupControlExtender)e.Row.FindControl("PopupControlExtender1");
string behaviorID = "PopupControlExtender1_" + e.Row.RowIndex;
PopupControlExtender1.BehaviorID = behaviorID;
ImageButton ImageButton1 = (ImageButton)e.Row.FindControl("ImageButton1");

string OnMouseOverScript = string.Format("$find('{0}').showPopup();", behaviorID);
string OnMouseOutScript = string.Format("$find('{0}').hidePopup();", behaviorID);

ImageButton1.Attributes.Add("onmouseover", OnMouseOverScript);
ImageButton1.Attributes.Add("onmouseout", OnMouseOutScript);
}}

最佳答案

我刚刚阅读了您的代码。在我这边,我以这种方式显示弹出窗口而获得成功

protected void gvTemplates_RowCreated(object sender, GridViewRowEventArgs e)
{
//GridView gv1 = (GridView)sender;
//foreach (GridViewRow item in gv1.Rows)
//{
if (e.Row.RowType == DataControlRowType.DataRow)
{
PopupControlExtender pce = e.Row.FindControl("PopupControlExtender1") as PopupControlExtender;
string behaviorID = "pce_" + e.Row.RowIndex;
pce.BehaviorID = behaviorID;
Panel pnl = (Panel)e.Row.FindControl("Panel2");
string OnMouseOverScript = string.Format("$find('{0}').showPopup();", behaviorID);
string OnMouseOutScript = string.Format("$find('{0}').hidePopup();", behaviorID);
pnl.Attributes.Add("onmouseover", OnMouseOverScript);
pnl.Attributes.Add("onmouseout", OnMouseOutScript);
}
//}
}

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string GetDynamicContent(string contextKey)
{
StringBuilder b = new StringBuilder();
b.Append("<table style='background-color:#f3f3f3; border: #4DB3A4 2px solid; ");
b.Append("width:100px;height:100px; font-size:8pt; font-family:'lucida grande', tahoma, verdana, arial, sans-serif;' cellspacing='0' cellpadding='3'>");
b.Append("<tr><td colspan='3' style='background-color:white;'>");
b.Append(contextKey);
b.Append("</td></tr>");
b.Append("</table>");
return b.ToString();
}

关于c# - 如何使用 PopupControlExtender 弹出 ASP.NET 控件而不是面板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28556661/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com