0

I have an asp.net page with 5 GridView controls all linked to the same SelectedIndexChanged event as follows

    <div id="containerOne" class ="containerLeft">
        <h2 class="WorkInProgressHeading">To Analyse</h2>
        <asp:LinkedGridView runat="server"  ID ="grdAwaitingAnalysis" CssClass="Grid" OnSelectedIndexChanged="grid_SelectedIndexChanged">
            <AlternatingRowStyle CssClass="GridAltItem"/>
            <RowStyle CssClass="GridItem"/>
            <SelectedRowStyle CssClass="GridSelectedItem"/>
        </asp:LinkedGridView>
    </div>
    <div id="containerTwo" class="containerLeft">
        <h2 class="WorkInProgressHeading">Analysing...</h2>
        <asp:LinkedGridView runat="server" ID="grdAnalysisInProgress" CssClass="Grid" OnSelectedIndexChanged="grid_SelectedIndexChanged">
            <AlternatingRowStyle CssClass="GridAltItem"/>
            <RowStyle CssClass="GridItem"/>
            <SelectedRowStyle CssClass="GridSelectedItem"/>
        </asp:LinkedGridView>
    </div> etc.....

In the code behind, the event handler is as follows

    protected void grid_SelectedIndexChanged(object sender, EventArgs e)
    {
        var sendingGrid = sender as LinkedGridView;

        if (sendingGrid.ID != "grdAwaitingAnalysis") grdAwaitingAnalysis.SelectedIndex = -1;
        if (sendingGrid.ID != "grdAnalysisInProgress") grdAnalysisInProgress.SelectedIndex = -1;
        if (sendingGrid.ID != "grdAwaitingReporting") grdAwaitingReporting.SelectedIndex = -1;
        if (sendingGrid.ID != "grdAwaitingInterp") grdAwaitingInterp.SelectedIndex = -1;
        if (sendingGrid.ID != "grdInterpInProgress") grdInterpInProgress.SelectedIndex = -1;

   }

I was surprised that this didnt cause a stackoverflow exception because when each selected index is set to -1 i expected the grid_SelectedIndexChanged event to fire again but it didn't.

Is this because it's a web page instead of a WPF / Winforms situation ? I'm relatively new to ASP.NET, so am I wrong in thinking about as similar to a WPF / WinForms app ?

Thanks.

4

1 回答 1

0

这是因为它是网页而不是 WPF

大概。在非 AJAX 表单中,如果索引与之前的呈现不同,IndexChanged则仅 在回发时触发事件。

在 WPF/Winforms 世界中,事件附加到实际控件,因此当值更改时,事件会立即触发。

请记住,该事件仅在索引实际更改时触发。将其设置为相同的值不会触发事件。

于 2013-04-29T13:41:37.007 回答