1

我有一个gridview,其中有一些列和查看详细信息链接按钮。我想打开一个弹出窗口,其中包含另一个包含一些详细信息的gridview。为此,我将商店编号作为命令参数从查看详细信息链接按钮传递。但是问题是弹出窗口正在打开,但服务器端事件 LinkViewDetail_Command 没有被调用,因为 gridview 没有显示任何内容。建议我对此代码进行一些修改或其他方式吗?

<asp:TemplateField HeaderText="View Detail" >
            <ItemTemplate>
             <asp:LinkButton ID="LinkButtonViewDetail" Text="View" runat="server"  CommandArgument='<%#Eval("StoreNumber").ToString()%>' OnCommand="LinkViewDetail_Command"/>
             <ajax:ModalPopupExtender runat ="server" ID="ModalPopupWarning" 
            TargetControlID="LinkButtonViewDetail"
            PopupControlID="PanelPopUp"  
            CancelControlID="ButtonCancel"
                            ></ajax:ModalPopupExtender>
            </ItemTemplate>
          </asp:TemplateField>



 Public Sub LinkViewDetail_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
    Try

        GridViewViewNewStoreTransitionStore.DataSource = m_DataAccess.GetFinalStoreCloseAcquisition(CInt(e.CommandArgument))
        GridViewViewNewStoreTransitionStore.DataBind()

    Catch ex As Exception
        Common.WriteLog(ex)
        Response.Redirect("..\Errors.aspx", False)
    End Try
End Sub
4

1 回答 1

1

将您的 ModalPopupExtender 放在网格视图之外并像这样初始化它

 <ajax:ModalPopupExtender runat ="server" ID="ModalPopupWarning" 
        TargetControlID="PanelPopUp" <!--dont use the LinkButtonViewDetail as a TargetControlID use the    id of any other control -->
        BehaviorID="PanelPopUpBI" 
        PopupControlID="PanelPopUp"  
        CancelControlID="ButtonCancel">
 </ajax:ModalPopupExtender>

然后使用网格视图中的 OnRowCreated 事件将详细视图链接注册为异步触发器

protected void OnRowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
       foreach (Control cells in e.Row.Controls)
       {
         foreach (Control link in cells.Controls)
         {
            if (link.GetType() == typeof(LinkButton))
            {
               // here i suppose that you have a master page
               (this.Master.FindControl("ToolkitScriptManager") as ScriptManager).RegisterAsyncPostBackControl(link);
            }
          }
       }
    }

}

在您的 aspx 文件中,使用此脚本在 ajax 请求完成时显示弹出窗口

 <script type="text/javascript">
  function pageLoad() { 
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);

        function endRequestHandler() {
            $find('PanelPopUpBI').show();
        }
    }
</script>
于 2012-05-25T11:26:50.593 回答