1

我是一名新的 ASP.NET 开发人员,我正在为公司的部门开发一个简单的 Intranet 注册系统。可用事件将列在 GridView 中,显示事件标题的第一列将作为链接按钮。我现在想要的是以下内容:

当用户单击其中一个事件标题时,将显示一个弹出窗口,其中显示带有注册按钮的 GridView 中已存在的事件信息。我是 AjaxToolKit ModalPopUp 扩展器。我几乎做了所有事情,但我不知道如何在 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

请注意,我不想在 GridView 中显示带有其他信息的 ID

4

1 回答 1

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

于 2012-08-13T04:27:34.823 回答