0

I have a ListView that's inside a UpdatePanel, UpdateMode = Conditional:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <table>
            <tr>
                <td>
                    <asp:ListView ID="SearchListView" runat="server">
                        <LayoutTemplate>
                            <div id="scrollDiv" onscroll="SaveScrollPosition();">
                                <table>
                                    <tr>
                                    ...
                                    </tr>
                                </table>
                            </div>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <tr>
                                <td align="right">
                                    <asp:LinkButton ID="lblUnitItem" runat="server" CommandName="Select"></asp:LinkButton>
                                </td>
                            </tr>
                        </ItemTemplate>
                        <SelectedItemTemplate>
                            <tr>
                                <td align="right">
                                    <asp:LinkButton ID="lblUnitItem" runat="server" CommandName="Select"></asp:LinkButton>
                                </td>
                            </tr>
                        </SelectedItemTemplate>
                    </asp:ListView>
                </td>
            </tr>
        </table>
    </ContentTemplate>
</asp:UpdatePanel>

Selecting a list item cause the whole page reloading instead of partial page refresh. I bound the listview to the datasource in the method "FillSearchListView", and implemented the "OnSearchListViewItemCommand" and "OnSearchListViewSelectedIndexChanging" events:

protected void OnSearchListViewSelectedIndexChanging(object sender, ListViewSelectEventArgs e)
{
    ((ListView)sender).SelectedIndex = e.NewSelectedIndex;
    FillSearchListView();
}

protected void OnSearchListViewItemCommand(object sender, ListViewCommandEventArgs e)
{
    switch (e.CommandName)
    {
        case "Select":
            ListViewDataItem dataItem = (ListViewDataItem)e.Item;
            this.CurrentId = decimal.Parse((string)e.CommandArgument);
            break;
    }
}

Any ideas why this isn't working? Thanks.

4

4 回答 4

2

在新版本的 ASP.NET 中,更改了在 ListView 等容器内生成控件的 ID。UpdatePanel 上的触发器无法解决此问题。

只需将 ClientIDMode="AutoID" 放在您的链接按钮(或其他控件)中,这样回发将是异步的。

于 2014-06-12T19:19:04.677 回答
1

嗨,在更新面板中使用触发

这是代码

  <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <table>
                            <tr>
                                <td>
                                    <asp:ListView ID="SearchListView" runat="server">
                                        <LayoutTemplate>
                                             </LayoutTemplate> 
                                        </asp:ListView> 
                                    </ContentTemplate> 
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="SearchListView" EventName="SelectedIndexChanged" />
                    </Triggers>
        </asp:UpdatePanel> 
于 2013-06-20T12:34:18.330 回答
0

添加属性:ChildrenAsTriggers="true"

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"   ChildrenAsTriggers="true" >

在此处查看 childerenastriggers

于 2013-06-20T12:28:45.013 回答
0

尝试这个

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <table>
            <tr>
                <td>
                    <asp:ListView ID="SearchListView" runat="server">
                        <LayoutTemplate>
                            <div id="scrollDiv" onscroll="SaveScrollPosition();">
                                <table>
                                    <tr>
                                        ...
                                    </tr>
                                </table>
                            </div>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <tr>
                                <td align="right">
                                    <asp:LinkButton ID="lblUnitItem" runat="server" CommandName="Select"></asp:LinkButton>
                                </td>
                            </tr>
                        </ItemTemplate>
                        <SelectedItemTemplate>
                            <tr>
                                <td align="right">
                                    <asp:LinkButton ID="lblUnitItem" runat="server" CommandName="Select"></asp:LinkButton>
                                </td>
                            </tr>
                        </SelectedItemTemplate>
                    </asp:ListView>
                </td>
            </tr>
        </table>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="SearchListView" EventName="SelectedIndexChanging" />
        <asp:AsyncPostBackTrigger ControlID="SearchListView" EventName="ItemCommand" />
    </Triggers>
</asp:UpdatePanel>
于 2013-06-20T12:37:09.030 回答