我的 GridView 的每一行都有一个按钮。当用户按下按钮时,我想显示一个显示文本的简单弹出窗口。部分文本是与特定行相关的 DataKeyName 。
我已尝试使用按钮触发的ModalPopupExtender myMPE ,并使用Panel myPanel 作为 PopupControlID 。问题是,我放置 DataKeyName 值的Panel的TextBox txtPanel 始终为空。我尝试在没有 myMPE 的情况下进行调试,并且Panel的 txtPanel 已正确填充。我想这会使回发搞得一团糟。
有人知道解决方案吗?
答案 0 :(得分:1)
您是否在模式弹出式面板上手动刷新了UpdaePanel?如果没有,请尝试手动刷新updatePanel&将其updateMode设置为Conditional。 检查以上示例 ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="Stylesheet" type="text/css" href="css/StyleSheet.css" />
<style type="text/css">
.modal
{
background-color: Aqua;
width: 150px;
height: 100px;
padding: 6px;
}
.modalBackground
{
background-color: #CCCCFF;
filter: alpha(opacity=40);
opacity: 0.5;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:UpdatePanel ID="upnGrid" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:GridView CssClass=".Grid-blue" ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="LinqDataSource1">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="SupplierID" HeaderText="SupplierID" SortExpression="SupplierID" />
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" SortExpression="CategoryID" />
<asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit" SortExpression="QuantityPerUnit" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
<asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder" />
<asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel" SortExpression="ReorderLevel" />
<asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbEdit" runat="server" OnClick="lbEdit_Click">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="DataClassesDataContext"
EntityTypeName="" TableName="Products">
</asp:LinqDataSource>
</div>
<ajaxToolkit:ModalPopupExtender BackgroundCssClass="modalBackground" ID="mpeDetails"
CancelControlID="btnClosePopup" TargetControlID="btnShowModal" PopupControlID="pnlDetails"
runat="server">
</ajaxToolkit:ModalPopupExtender>
<asp:Button ID="btnShowModal" runat="server" Text="Button" Style="display: none" />
<asp:Panel ID="pnlDetails" CssClass="modal" runat="server" Style="display: none">
<asp:UpdatePanel ID="upnDetails" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<label>
ID:</label><asp:TextBox ID="txtID" runat="server"></asp:TextBox>
<br />
<label>
Name:</label>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<br />
</ContentTemplate>
</asp:UpdatePanel>
<div>
<asp:Button ID="btnClosePopup" runat="server" Text="Cancel" /></div>
</asp:Panel>
</form>
</body>
</html>
.CS
protected void lbEdit_Click(object sender,EventArgs e) { LinkButton lbTemp =(LinkButton)sender;
if (lbTemp != null) { GridViewRow grow =(GridViewRow) lbTemp.NamingContainer; int id = Convert.ToInt32(GridView1.DataKeys[grow.RowIndex][0].ToString()); mpeDetails.Show(); txtID.Text = id.ToString(); upnDetails.Update(); } }