2012-08-13 62 views
1

我是一名新的ASP.NET開發人員,我正在爲公司的部門開發一個簡單的Intranet註冊系統。可用事件將在GridView中列出,第一列顯示事件標題將作爲鏈接按鈕。我現在想要的是:如何顯示Ajax ModalPopUp Extender中的GridView中列出的項目信息?

當用戶點擊其中一個事件標題時,會彈出一個窗口,顯示GridView中已存在的事件信息,並帶有Register按鈕。我是AjaxToolKit ModalPopUp Extender。我做了幾乎所有的事情,但我不知道如何在ModalPopUp中顯示該事件的信息。

你能幫我解決嗎?

我的代碼隱藏(C#):

protected void lnkTitle_Click(object sender, EventArgs e) 
{ 
    //to get the GridViewRow from the sender, so we can get the datakey we need 
    GridViewRow gvrow = (GridViewRow)(((LinkButton)sender)).NamingContainer; 
    HiddenField1.Value = ListOfAvailableEvents_GrivView.DataKeys[gvrow.RowIndex].Value.ToString(); 

    //show the modalPopUp 
    modalPopupExtender1.Show(); 
} 

我的ASP.NET代碼:

<asp:GridView ID="ListOfAvailableEvents_GrivView" runat="server" AutoGenerateColumns="False" 
    DataKeyNames="ID" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" 
    AllowPaging="True" PageSize="5"> 
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> 
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" CssClass="generaltext" /> 
    <Columns> 
     <asp:TemplateField HeaderText="Title"> 
      <ItemTemplate> 
       <asp:LinkButton ID="lnkTitle" runat="server" Text='<%# Eval("Title") %>' OnClick="lnkTitle_Click"></asp:LinkButton> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" /> 
     <asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" /> 
     <asp:BoundField DataField="StartDateTime" HeaderText="Start Date & Time" SortExpression="StartDateTime" /> 
     <asp:BoundField DataField="EndDateTime" HeaderText="End Date & Time" SortExpression="EndDateTime" /> 
    </Columns> 
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> 
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> 
    <HeaderStyle Font-Bold="True" CssClass="complete" /> 
    <EditRowStyle BackColor="#999999" /> 
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> 
</asp:GridView> 

<asp:Button ID="btnModalPopUp" runat="server" Style="display: none" /> 
<ajaxToolkit:ModalPopupExtender ID="modalPopupExtender1" runat="server" TargetControlID="btnModalPopUp" 
    PopupControlID="pnlPopUp" BackgroundCssClass="popUpStyle" PopupDragHandleControlID="panelDragHandle" 
    OkControlID="OKButton"> 
</ajaxToolkit:ModalPopupExtender> 

<asp:HiddenField ID="HiddenField1" runat="server" /> 
<asp:Panel ID="pnlPopUp" runat="server" CssClass="popUpStyle"> 
    <asp:Button ID="confirmButton" runat="server" Text="Register" OnClick="btnSendConfirmationEmail_Click" /> 
    <asp:Button ID="OKButton" runat="server" Text="Cancel" /> 
</asp:Panel> 

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PM_RegistrationSysDBConnectionString %>" 
    SelectCommand="SELECT  ID, Title, Description, Location, StartDateTime, EndDateTime 
        FROM   dbo.Events 
        WHERE  (IsActive = 1) 
        ORDER BY ID DESC"> 
</asp:SqlDataSource> 

僅供參考,我在我的數據庫中的表,我感到它綁定到GridView:

Events Table: ID, Title, Description, Location, StartDateTime, EndDateTime 

請注意我不想在GridV中顯示其他信息的ID iew

+0

你爲什麼試圖顯示一個隱藏的字段我認爲這將是更esier和更精確的,如果你將填充從代碼隱藏的信息基於選定的行的信息 – 2012-08-13 04:19:37

回答

3

這裏有幾個鏈接顯示了一個很好的教程,在我看來,它會幫助您在不使用代碼隱藏的情況下使用客戶端來實現您想要的內容,因此您可以避免頁面刷新,因爲用戶單擊鏈接按鈕

http://technico.qnownow.com/using-ajax-modal-popup-extender-asp-net-gridview-control/

http://shibashishdotnetocean.blogspot.com/2011/12/modalpopupextender-in-gridview.html

http://www.dotnetcurry.com/ShowArticle.aspx?ID=212

http://kishor-naik-dotnet.blogspot.com/2011/10/ajax-modalpopupextender-in-gridview.html

+0

感謝您的幫助。對此,我真的非常感激。 – 2012-08-13 04:46:21

相關問題