【问题标题】:Gridview not displaying in Panel associated with a ModalPopupExtenderGridview 未显示在与 ModalPopupExtender 关联的面板中
【发布时间】:2011-04-04 11:55:00
【问题描述】:

我有两个与 modalpopupextender 关联的图像按钮。当我单击 imagebutton1 时,它会打开面板,在该面板内有一个加载信息的网格。但是,当我单击 Imagebutton2 时,它会打开面板,但不会显示 gridview,即使该 gridview 标记位于该面板下也是如此。

我是网络新手,请帮忙。谢谢你。请在下面找到代码:

<asp:Panel ID="PNL" ScrollBars="Auto" runat="server" Style="border: 2px solid Black; display: none; width: auto;
        background-color: White; padding: 20px; text-align: center;" Height="444">
        <asp:Label ID="LabelCount" runat="server" Text="Label" Font-Size="Large" 
            style="text-align: center"></asp:Label>
        <asp:Button ID="ButtonOK" Text="OK" runat="server" />
        <%-- Area for keeping POPUP grid ot window or picture DO NOT PUT UNDER TABLE Taj 3-Jan-2010--%>                

            <asp:GridView ID="gvUsersWHYME" runat="server" BackColor="White" BorderColor="#010101"
            BorderStyle="None" CaptionAlign="Top" CellPadding="1" CellSpacing="2" GridLines="None"
            Style="margin-left: 0px" DataSourceID="SqlDataSource0" AutoGenerateColumns="False"
            EnableTheming="False" AllowSorting="True" 
            OnRowDataBound="gvUsers_RowDataBound">
            <Columns>
                <asp:TemplateField HeaderText="Roles" Visible="False">
                    <HeaderTemplate>
                        <asp:CheckBox ID="chkAll" runat="server" 
                            onclick="javascript:SelectAllCheckboxesSpecific(this);" />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="chkGenerate" runat="server" 
                            onclick="javascript:HighlightRow(this);" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="ProjectNum" HeaderText="Release#" SortExpression="ProjectNum"
                    ReadOnly="true" />
                    <asp:BoundField DataField="IPMRefNum" HeaderText="IPM Ref #" 
                    SortExpression="IPMRefNum" />
                <asp:BoundField DataField="TestprojectNo" HeaderText="Release Description" SortExpression="TestprojectNo"
                    ItemStyle-Width="444">
                    <ItemStyle Width="444px"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="ProjectName" HeaderText="ProjectName" SortExpression="ProjectName"
                    Visible="False" />

                <asp:BoundField DataField="ProposedPhaseName" HeaderText="Proposed Phase Name" ItemStyle-Wrap="False"
                    SortExpression="ProposedPhaseName">
                    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="DependencyList" HeaderText="Dependency List" 
                    SortExpression="DependencyList" />
                <asp:BoundField DataField="QA_Planned_EndDate" HeaderText="Release Handover Date"
                    SortExpression="QA_Planned_EndDate" DataFormatString="{0:d}" 
                    ItemStyle-Wrap="False">
                    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Applications" HeaderText="Impacted Application(s)" 
                    SortExpression="Applications" />
                <asp:BoundField DataField="AppCount" HeaderText="Count" 
                    SortExpression="AppCount" />
            </Columns>
            <FooterStyle BackColor="White" ForeColor="#330099" />
            <RowStyle BackColor="White" ForeColor="#330099" />
            <HeaderStyle BackColor="#ACCDF6" Font-Bold="True" ForeColor="#FFFFCC" />
        </asp:GridView>
        <asp:Label  ID="lblCountImpacted" runat="server" Text="Total Impacted App."  
            Font-Size="Large"></asp:Label>            
    </asp:Panel>
    <br />
    <br />
    <br />
    <br />
    <br />
     <asp:Panel ID="Panel1" ScrollBars="Auto" runat="server" Style="border: 2px solid Black; display: none; width: auto;
        background-color: White; padding: 20px; text-align: center;" Height="444">
        <asp:Button ID="Button1" Text="OK" runat="server" />
     <asp:GridView ID="GridView4" runat="server" BackColor="White" BorderColor="#010101"
            BorderStyle="None" CaptionAlign="Top" CellPadding="1" CellSpacing="2" GridLines="None"
            Style="margin-left: 0px" DataSourceID="SqlDataSource6" AutoGenerateColumns="False"
            EnableTheming="False" AllowSorting="True" 
            OnRowDataBound="GridView4_RowDataBound">
            <Columns>                
                <asp:BoundField DataField="ProjectNum" HeaderText="Release#" SortExpression="ProjectNum"
                    ReadOnly="true" />
                    <asp:BoundField DataField="IPMRefNum" HeaderText="IPM Ref #" 
                    SortExpression="IPMRefNum" />
                <asp:BoundField DataField="TestprojectNo" HeaderText="Release Description" SortExpression="TestprojectNo"
                    ItemStyle-Width="444">
                    <ItemStyle Width="444px"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="ProjectName" HeaderText="ProjectName" SortExpression="ProjectName"
                    Visible="False" />

                <asp:BoundField DataField="ProposedPhaseName" HeaderText="Proposed Phase Name" ItemStyle-Wrap="False"
                    SortExpression="ProposedPhaseName">
                    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="DependencyList" HeaderText="Dependency List" 
                    SortExpression="DependencyList" />
                <asp:BoundField DataField="QA_Planned_EndDate" HeaderText="Release Handover Date"
                    SortExpression="QA_Planned_EndDate" DataFormatString="{0:d}" 
                    ItemStyle-Wrap="False">
                    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
            </Columns>
            <FooterStyle BackColor="White" ForeColor="#330099" />
            <RowStyle BackColor="White" ForeColor="#330099" />
            <HeaderStyle BackColor="#ACCDF6" Font-Bold="True" ForeColor="#FFFFCC" />
        </asp:GridView>
     </asp:Panel>

【问题讨论】:

    标签: asp.net gridview asp.net-ajax panel modalpopupextender


    【解决方案1】:

    我已经创建了一个示例代码。与您的问题类似。

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MasterDetail.aspx.cs"
    Inherits="MasterDetail" %>
    
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxtoolkit" %>
    <!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>Untitled Page</title>
    </head>
    <body>
       <form id="form" runat="server">
           <asp:ScriptManager ID="scriptManager" runat="server" />
           <div>
               <asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
                   <ContentTemplate>
                       <asp:Label ID="lblTitle" runat="server" Text="Customers" BackColor="lightblue" Width="95%" />
                       <asp:GridView ID="gvCustomers" runat="server" DataKeyNames="Id" AutoGenerateColumns="false"
                           AllowPaging="true" AllowSorting="true" PageSize="10" Width="95%">
                           <AlternatingRowStyle BackColor="aliceBlue" />
                           <HeaderStyle HorizontalAlign="Left" />
                           <Columns>
                               <asp:TemplateField ControlStyle-Width="50px" HeaderStyle-Width="60px">
                                   <ItemTemplate>
                                       <asp:Button ID="btnViewDetails" runat="server" Text="Details" OnClick="BtnViewDetails_Click" />
                                   </ItemTemplate>
                               </asp:TemplateField>
                               <asp:BoundField DataField="Id" HeaderText="ID" SortExpression="Id" ReadOnly="true" />
                               <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="contactname" ReadOnly="true" />
                           </Columns>
                       </asp:GridView>
                   </ContentTemplate>
               </asp:UpdatePanel>
               <asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
               <ajaxtoolkit:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup"
                   PopupControlID="pnlPopup" CancelControlID="btnClose" BackgroundCssClass="modalBackground" />
               <asp:Panel ID="pnlPopup" runat="server" Width="500px" Style="display: none">
                   <asp:UpdatePanel ID="updPnlCustomerDetail" runat="server" UpdateMode="Conditional">
                       <ContentTemplate>
                           <asp:Label ID="lblCustomerDetail" runat="server" Text="Customer Detail" BackColor="lightblue"
                               Width="95%" />
                           <asp:DetailsView ID="dvCustomerDetail" runat="server" DefaultMode="Edit" Width="95%"
                               BackColor="white" />
                       </ContentTemplate>
                   </asp:UpdatePanel>
                   <div align="right" style="width: 95%">
                       <asp:Button ID="btnSave" runat="server" Text="Save"
    OnClientClick="alert('Sorry, but I didnt implement save '); return false;"
                           Width="50px" />
                       <asp:Button ID="btnClose" runat="server" Text="Close" Width="50px" />
                   </div>
               </asp:Panel>
           </div>
       </form>
    </body>
    </html>
    
    
    
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class MasterDetail : System.Web.UI.Page
    {
        DataSet ds;
        protected void Page_Load(object sender, EventArgs e)
        {
    
            ds = Data();
            if (!this.IsPostBack)
            {
                if (Session["parent"] == null)
                {
                    gvCustomers.DataSource = ds.Tables["Parent"];
                    gvCustomers.DataBind();
                }
                else
                {
                    gvCustomers.DataSource = Session["Parent"] as DataTable;
                    gvCustomers.DataBind();
    
                }
            }
    
        }
        private DataSet Data()
        {
    
            DataTable dt = new DataTable();
            dt.Columns.Add("Id", typeof(int));
            dt.Columns.Add("Name", typeof(string));
    
            dt.Rows.Add(new object[] { 1, "aaaa" });
            dt.Rows.Add(new object[] { 2, "bbbb" });
            dt.Rows.Add(new object[] { 3, "cccc" });
            dt.TableName = "Parent";
    
    
    
    
            DataTable dtc = new DataTable();
            dtc.Columns.Add("Id", typeof(int));
            dtc.Columns.Add("Qul", typeof(string));
    
            dtc.Rows.Add(new object[] { 1, "aaaa" });
            dtc.Rows.Add(new object[] { 2, "bbbb" });
            dtc.Rows.Add(new object[] { 3, "bbbb" });
            dtc.TableName = "Child";
    
    
            DataSet ds = new DataSet();
    
            ds.Tables.Add(dt);
            ds.Tables.Add(dtc);
            Session["Parent"] = dt;
    
            return ds;
    
        }
        protected void BtnViewDetails_Click(object sender, EventArgs e)
        {
            //  get the gridviewrow from the sender so we can get the datakey we need
            Button btnDetails = sender as Button;
            GridViewRow row = (GridViewRow)btnDetails.NamingContainer;
    
            //  extract the id from the row whose details button originated the postback.
            //  grab the customerid and feed it to the customer details datasource
            //  finally, rebind the detailview
            DataView dv = new DataView(ds.Tables["Child"]);
    
            dv.RowFilter = "Id=" + Convert.ToString(this.gvCustomers.DataKeys[row.RowIndex].Value);
            dvCustomerDetail.DataSource = dv;
            dvCustomerDetail.DataBind();
    
            //  update the contents in the detail panel
            this.updPnlCustomerDetail.Update();
            //  show the modal popup
            this.mdlPopup.Show();
        }  
    }
    

    【讨论】:

    • 我在某些情况下错过了gridview的绑定方法吗?我没有在我的场景中使用更新面板
    • 我用过更新面板,你可以根据需要修改代码
    • 你可以在没有 UpdatePanel 的情况下使用 ModalPopupExtender,但你仍然需要一个 ScriptManager。
    猜你喜欢
    • 1970-01-01
    • 2011-07-31
    • 1970-01-01
    • 2011-02-13
    • 1970-01-01
    • 1970-01-01
    • 2016-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多