2012-03-07 41 views
0

我有一個按鈕放置在我的GridView的每一行上。當用戶按下按鈕時,我想顯示一個簡單的彈出窗口,在其中顯示文本。部分文本是與特定行相關的DataKeyName彈出簡單的文本按鈕點擊

我已經嘗試過用ModalPopupExtender myMPE由按鈕觸發和我使用的面板myPanelPopupControlID。問題在於TextBox txtPanel的面板在哪裏,我把DataKeyName的值始終是空的。我試圖調試沒有myMPE和麪板的txtPanel正確填寫。我想這會讓回帖混亂。

任何人都知道一個解決方案嗎?

回答

1

您是否正在手動刷新模式彈出式面板上的UpdaePanel?如果沒有,請嘗試手動刷新updatePanel &將其updateMode設置爲有條件。 檢查例如 以上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

保護無效lbEdit_Click(對象發件人,EventArgs的) { 的LinkBut​​ton lbTemp =(LinkBut​​ton的)發送者;

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(); 
    } 
}