0

我有一个ListViewwith LinkButtons。我正在使用OnItemCommand带有 a 的方法CommanName来打开一个对话框。

如果用户单击LinkButton,我希望它打开一个对话框(带有控件等)。但是我每次都遇到同样的错误:

System.InvalidOperationException:ListView“myListView”有一个 SelectedIndexChanging-Event 执行,未处理。

我的代码:aspx

...

<asp:HiddenField ID="hidForModel" runat="server" />

    <asp:scriptmanager id="ScriptManager1" runat="server">
       </asp:scriptmanager> 

       <asp:modalpopupextender id="PopUpDialog" 
                runat="server" cancelcontrolid="btnCancel" 
                okcontrolid="btnOkay" targetcontrolid="hidForModel" 
                popupcontrolid="Panel1" popupdraghandlecontrolid="PopupHeader" 
                drag="true" backgroundcssclass="ModalPopupBG" >

</asp:modalpopupextender>

            <div class="popupConfirmation" id="Panel1" runat="server" >
              <asp:Panel runat="server" ID="PopupHeader" CssClass="modalPopup">Benutzerinformationen</asp:Panel>
                <div class="Body">
                    Hallo
                    <asp:TextBox ID="txtVorname" runat="server"></asp:TextBox>
                    <asp:Button id="btnOkay" runat="server" text="Speichern" />
                    <asp:Button id="btnCancel" runat="server" text="Abbrechen" />
                </div>

            </div>

...

 <asp:ListView runat="server" ID="myListView" OnItemCommand="myListView_ItemCommand">

        <LayoutTemplate>
            <table id="UserTable" runat="server" border="0" width="800" cellpadding="0" cellspacing="0">
                <tr style="background-color:#E5E5FE" class="TableClass">
                    <th id="th1" runat="server"><asp:LinkButton ID="lnkBenutzer" runat="server" >id_Benutzer</asp:LinkButton></th>
                    <th id="th2" runat="server"><asp:LinkButton ID="lnkemail" runat="server" >id_Email</asp:LinkButton></th>
                    <th id="th3" runat="server"><asp:LinkButton ID="lnkVorname" runat="server" >id_Vorname</asp:LinkButton></th>
                    <th id="th4" runat="server"><asp:LinkButton ID="lnkNachname" runat="server" >id_Nachname</asp:LinkButton></th>
                    <th id="th5" runat="server"><asp:LinkButton ID="lnkTelefon" runat="server" >id_Telefon</asp:LinkButton></th>
                </tr>
                <tr runat="server" id="ItemPlaceholder">
                </tr>
            </table>
        </LayoutTemplate>

        <ItemTemplate>

            <tr class="TableClass">    
                <td align="left" ><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label1" Text='<%# Eval("Benutzername") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink"  CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label2" Text='<%# Eval("eMail") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label3" Text='<%# Eval("Vorname") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink"  CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label4" Text='<%# Eval("Nachname") %>' runat="server"  /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink"  CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label5" Text='<%# Eval("Telefonnummer") %>' runat="server"  /></td>

              <td align="left"><asp:Label ID="Label6" Text='<%# Eval("GUID") %>' runat="server" Visible="False" /></td>

            </tr>

        </ItemTemplate>

        <AlternatingItemTemplate>

            <tr class="TableClass"> 

                <td align="left" ><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label1" Text='<%# Eval("Benutzername") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label2" Text='<%# Eval("eMail") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink"  CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label3" Text='<%# Eval("Vorname") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink"  CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label4" Text='<%# Eval("Nachname") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label5" Text='<%# Eval("Telefonnummer") %>' runat="server" /></td>

                <td align="left"><asp:Label ID="Label6" Text='<%# Eval("GUID") %>' runat="server" Visible="False" /></td>

            </tr>

        </AlternatingItemTemplate>

        </asp:ListView>

...

c#代码:

protected void myListView_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                txtVorname.Text = "test";

                PopUpDialog.Show();  //<-- Here is the error 

            }
        }

我可以使用Button(用于测试)打开对话框,但不能使用LinkButton.

4

4 回答 4

2
protected void myListView_ItemCommand(object sender, ListViewCommandEventArgs e)
{
 if (e.CommandName == "Select")
  {
  ModalPopupExtender popUp = (ModalPopupExtender)lvAlbum.FindControl("PopUpDialog");
  popUp.Show();
  }
}
于 2012-12-14T04:12:44.780 回答
1

您只需要SelectedIndexChanging处理ListView.

标记

<asp:ListView runat="server" ID="myListView" OnItemCommand="myListView_ItemCommand"
    OnSelectedIndexChanging="myListView_SelectedIndexChanging" >

代码隐藏:

protected void myListView_SelectedIndexChanging(object sender, EventArgs e)
{

}

ListView如果它们触发,则需要处理其中的某些事件。如果这些事件尝试触发(例如单击具有“Select”的“CommandName”触发 SelectedIndexChanging 事件的列表项)并且未处理它们,则会收到与您提到的错误类似的错误。

于 2012-08-14T12:26:38.863 回答
0

不要使用命令 text Select。由于某种原因,它使弹出窗口不显示。例如执行以下操作:

if(e.CommandName == "ShowPopup")

这解决了我的问题。

于 2014-03-05T14:53:15.877 回答
0

我的解决方案需要特定的 ajax 脚本管理器。asp 没有用。

<ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajax:ToolkitScriptManager>

于 2022-01-18T16:22:20.457 回答