2

我有一个带有约会信息的网格视图。我想做的是在每个单元格中都有一个链接按钮(将在运行时创建)并打开一个显示约会详细信息的模式弹出窗口。任何帮助将不胜感激。

到目前为止,我已经有了,但它不会触发链接按钮

<asp:GridView ID="Grd" runat="server" AutoGenerateColumns="true" onrowdatabound="Grd_RowDataBound"></asp:GridView><asp:Button ID="btnShowPopup" style="display:none" runat="server"  />
<ajaxToolkit:ModalPopupExtender
ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlpopup" CancelControlID="ImgCancel" ></ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" Width="400px" ><!--Show Details--!>
 <asp:ImageButton ID="imgCancel"  AlternateText="cancel"  Height="25" Width="25" runat="server" ImageAlign="Right" />
</asp:Panel>

后面的代码

protected void Grd_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //Split out the visit details & format
            for (int i = 0; i <= e.Row.Cells.Count - 1; i++)
            {

                LinkButton lnk = new LinkButton();
                lnk.Text = "Details for:" + "<br />" + e.Row.Cells[i].Text; 

                lnk.CommandName = "ShowDetails";
                lnk.Command += LinkButton_Command;
                e.Row.Cells[i].Controls.Add(lnk);


            }



        }
    }
    protected void LinkButton_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "ShowDetails")
        {

            LinkButton btndetails = sender as LinkButton;

            GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer;

            this.ModalPopupExtender1.Show();


        }
    }
4

2 回答 2

0

在您的模式弹出窗口中,唯一的内容应该是一个空的 iframe。然后编写一个javascript函数如下:

function showPopup(target, link, width, height)
{
    var frame = document.getElementById('popupIframe');
    frame.src = link;
    frame.width = width;
    frame.height = height;
    var location = Sys.UI.DomElement.getLocation(target);
    var popup = $find('Popup');
    popup.set_X(location.x);
    popup.set_Y(location.y);
    popup.show();
}

然后在您的链接按钮中添加:

OnClientClick="showPopup(this, your_details_page_with_querystring_params, width, height)
于 2013-02-26T13:35:49.163 回答
0

最重要的是,您需要确保LinkButton在回发时重新创建动态控件,以便正确连接事件。由于您LinkButtonsGrd_RowDataBound处理程序中创建了,它仅在您调用时被调用BindData()(并且您不会在回发时调用它),所以您的事件不会连接。因此,如果您的代码看起来像这样:

if (!IsPostBack)
{
     Grd.BindData();
}

尝试删除if(!IsPostBack)检查,并始终在 Page_Load 上调用 BindData()。

于 2012-11-06T16:04:50.043 回答