2012-02-04 63 views
1

我在我的数据库中有以下表格:如何在GridView中使用ModalPopUpExtender?

建议日志表: ID,标题,描述。

Employee表:用户名,姓名

分部表: DivisionCode,DivisionName

我想说明表由SuggestionID,SuggestionTitle,EmployeeName和DivisionName的,当用户点击只和建议标题,将会显示一个弹出窗口和建议的描述。

因为我是ASP.NET初学者开发人员,所以我试图按照this tutorial来获得它,但我失败了。

我所做的是以下几点:

ASP.NET代码:

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
    <ContentTemplate> 
     <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
      AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" 
      DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound"> 
      <Columns> 
       <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
        ReadOnly="True" SortExpression="ID" /> 
       <asp:TemplateField HeaderText="Title"> 
        <ItemTemplate> 
         <asp:LinkButton runat="server" ID="lnkSuggestionTitle" 
             Text='<%#Eval("Title") %>' 
             OnClick="lnkSuggestionTitle_Click"> 
             </asp:LinkButton> 
        </ItemTemplate> 
       </asp:TemplateField> 
       <%--<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />--%> 
       <asp:BoundField DataField="Description" HeaderText="Description" 
        SortExpression="Description" /> 
       <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> 
       <asp:BoundField DataField="Username" HeaderText="Username" 
        SortExpression="Username" /> 
       <asp:BoundField DataField="DivisionName" HeaderText="Division" 
        SortExpression="DivisionName" /> 
      </Columns> 
     </asp:GridView> 

     <asp:Button runat="server" ID="btnModalPopUp" style="display:none" /> 

     <AjaxToolkit:ModalPopupExtender ID="modalPopUpExtender1" 
             runat="server" TargetControlID="btnModalPopUp" PopupControlID="pnlPopUp" BackgroundCssClass="modalBackground" 
             OkControlID="btnOk" X="20" Y="100"> 
     </AjaxToolkit:ModalPopupExtender> 

     <asp:Panel runat="server" ID="pnlPopUp" CssClass="confirm-dialog"> 
      <asp:GridView ID="GridView2" runat="server"> 
      </asp:GridView> 
     </asp:Panel> 

     </ContentTemplate> 
     </asp:UpdatePanel> 
     <br /> 

     <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="<%$ ConnectionStrings:testConnectionString %>" 
      SelectCommand="SELECT  dbo.SafetySuggestionsLog.ID, dbo.SafetySuggestionsLog.Title, dbo.SafetySuggestionsLog.Description, dbo.employee.Name, dbo.SafetySuggestionsLog.Username, 
         dbo.Divisions.DivisionName 
FROM   dbo.employee INNER JOIN 
         dbo.SafetySuggestionsLog ON dbo.employee.Username = dbo.SafetySuggestionsLog.Username INNER JOIN 
         dbo.Divisions ON dbo.employee.DivisionCode = dbo.Divisions.SapCode"> 
     </asp:SqlDataSource> 

代码隐藏:

protected void lnkSuggestionTitle_Click(object sender, EventArgs e) 
    { 
     LinkButton lnkSuggestionTitle = sender as LinkButton; 
     string strSuggestionTitle = lnkSuggestionTitle.Text; 

     string strConnectionString = ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString; 
     string strSelect = "SELECT ID, Title, Description FROM dbo.SafetySuggestionsLog"; 
     SqlConnection sqlCon = new SqlConnection(); 
     sqlCon.ConnectionString = strConnectionString; 
     SqlCommand cmdSuggestionDetails = new SqlCommand(); 
     cmdSuggestionDetails.Connection = sqlCon; 
     cmdSuggestionDetails.CommandType = System.Data.CommandType.Text; 
     cmdSuggestionDetails.CommandText = strSelect; 
     cmdSuggestionDetails.Parameters.AddWithValue("@Title", strSuggestionTitle); 
     sqlCon.Open(); 

     SqlDataReader dReader = cmdSuggestionDetails.ExecuteReader(); 
     GridView1.DataSource = dReader; 
     GridView1.DataBind(); 
     sqlCon.Close(); 
     modalPopUpExtender1.Show(); 
    } 

一切都很顺利和平稳,但在网站上,当我点击其中一个标题时,我没有得到ModalPopUp。另外,我在Internet Explorer浏览器,这当我打开它,它给了我下面的描述中左下角的错误通知:

**

Sys.ArgumentNullException:值不能为空值。参数名: 元素

**

我不知道这是为什么发生。请帮忙吗?

+0

尝试从标记中删除'DataSourceId'属性。当DataSource通过Source和'Code-Behind'指定时,DataControl无法填充。希望这有助于 – Deeptechtons 2012-02-05 05:25:34

+0

感谢您的帮助。现在,我得到了另一个错误:Sys.ArgumentNullException:值不能为空。参数名称:元素。 – 2012-02-05 05:39:21

回答

3

此问题通常是一个错误的OkControlID或CancelControlID(通过here),在这种情况下可能是“btnOk”。

0

从@ PeterX的建议来看,是的,您的面板声明缺少很多东西。

我会重做这个像这样的东西,这是我在另一个更大的GridView控制中使用。

      <ajaxToolkit:ModalPopupExtender ID="mpeEndorsed" runat="server" 
           BackgroundCssClass="modalBackground" 
           PopupControlID="pnlEndorsed" 
           OkControlID="btnEndorsed" 
           CancelControlID="btnNotEndorsed" 
           PopupDragHandleControlID="dvHdr" 
           Drag="true" 
           TargetControlID="cbEndorsed"> 
          </ajaxToolkit:ModalPopupExtender> 
          <asp:Panel ID="pnlEndorsed" runat="server" CssClass="pnlEndorsed" style="display:none"> 
           <div id="dvHdr"> 
            <asp:Label ID="Label3" runat="server">** CONTACT LOG **</asp:Label> 
           </div> 
           <div id="dvBody"> 
            <table style="text-align:center; width:100%"> 
             <tr> 
              <asp:GridView ID="gvContactLog" runat="server" ForeColor="#333333" GridLines="None" AllowPaging="true" PageSize="8" Font-Size="X-Small" CellPadding="4" AllowSorting="True" AutoGenerateColumns="False"> 
              </asp:GridView> 
             </tr> 
             <tr> 
              <td> 
               <asp:Button ID="btnEndorsed" runat="server" Text="YES" /> 
               <asp:Button ID="btnNotEndorsed" runat="server" Text="NO" /> 
              </td> 
             </tr> 
            </table> 
           </div> 
          </asp:Panel> 

注意在GridView 弹出面板里面是一个骨架,即,必须为从JavaScript代码隐藏或建立得到它是有用的。

在其整体定义一个GridView(数据源有,字段等等)弹出面板里面,这里面另一个更大的GridView(在我的情况),不起作用!你会看到一个混乱的屏幕和各地的东西。我想这是AjaxToolKit的限制,混合了客户端和服务器端的功能。

相关问题