代码之家  ›  专栏  ›  技术社区  ›  jhunter

NET和列表框

  •  1
  • jhunter  · 技术社区  · 17 年前

    我有一个UpdatePanel,里面有两个列表框。我希望发生的是,当页面加载时,第一个列表框中会填充一些数据。当用户选择项目时,应使用相关数据填充第二个列表框。

    下面是发生的情况,第一个列表框中填充了数据,用户选择了一个项目,并触发SelectedIndexChanged事件,但是在方法可以看到选择了哪个项目之前,选择被清除了?

    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
    <ContentTemplate>
        <table class="listBoxTable">
            <thead>
                <tr>
                    <th>
                        Please select a magazine to add articles to.</th>
                </tr>
            </thead>
            <tr>
                <td>                    
                    <asp:ListBox ID="lbMagazines" runat="server" Height="300px" Width="250px" 
                        onselectedindexchanged="lbMagazines_SelectedIndexChanged" DataTextField="Title" 
                        DataValueField="Id" AutoPostBack="True">
    
                    </asp:ListBox>
                </td>
                <td>                    
                    <asp:ListBox ID="lbIssues" runat="server" Height="300px" Width="250px" 
                        Enabled="False" DataTextField="Title" DataValueField="Id">
    
                    </asp:ListBox>
                </td>
            </tr>
        </table>
    </ContentTemplate>
    </asp:UpdatePanel>
    
    3 回复  |  直到 17 年前
        1
  •  3
  •   Darin Dimitrov    17 年前

    如果只需要更改第二个列表框的内容,则将第一个列表框置于UpdatePanel之外并使用触发器属性更合适:

    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="lbMagazines" EventName="OnSelectedIndexChanged" />
    </Triggers>
    

        2
  •  2
  •   Gavin Miller    17 年前

    听起来您的初始列表绑定代码没有包装在页面中。IsPostBack。

    If (!Page.IsPostBack)
    {
        //List bind code
    }
    

        3
  •  1
  •   achinda99    17 年前

    根据所提供的信息,我最初的想法是在页面加载时重新填充LBMagazine,这样当它到达事件时,selecteditem/索引就会被清除。

    推荐文章