开发者

How do I trap the SelectedIndexChange event of a DropDownList that is in a ModalPopupExtender extender in a Gridview?

I have a GridView that is data-bound to a generic list of objects. Each row has a project that has to be billed to various accounts. Each project has a Property that is a generic list of the Accounts and Amounts being billed - that 'child list' is displayed in a ListView embedded in one of the columns of the GridView.

When the user clicks the "Edit" link on any given line, in the GridView's "RowEditing" event, I populate all the fields in the hidden popup panel. When the user clicks the LinkButton that is identified in the ModalPopupExtender, the panel is shown with all the appropriate data. One item is a DropDownList bound to a .NET generic list of account objects that the user can choose from.

My problem is that the "OnSelectedIndexChanged" event isn't firing until AFTER the user has clicked on the ImageButton that I have set up as the "OK" button (using the OnCommand, CommandName and CommandArgument attributes).

Here's an attempt at showing how the code is:

<asp:Panel runat="server" ID="pnlBilling">
<asp:GridView runat="server" ID="grdBilling" AutoGenerateColumns="False" 
    Width="100%" Caption="" AutoGenerateEditButton="True">
    <Columns> '  Only showing the pertinent column
        <asp:TemplateField ItemStyle-VerticalAlign="Top" HeaderText="Project">
            <ItemTemplate>
                <asp:Label ID="lblProject" runat="server" text='<%#Eval("Project")%>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:Label ID="lblProject" runat="server" text='<%#Eval("Project")%>' />
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Billing">
            <ItemTemplate>
                <asp:Table ID="tblBillEntries" runat="server" Width="100%">
                    <asp:TableHeaderRow>
                        <asp:TableCell>Current:&nbsp;</asp:TableCell>
                        <asp:TableCell HorizontalAlign="Right"><asp:Label ID="lblAmount" runat="server" Text='<%#Bind("Amount", "{0:c}")%>' /></asp:TableCell>
                    </asp:TableHeaderRow>
                    <asp:TableRow>
                        <asp:TableCell ColumnSpan="2">
              开发者_StackOverflow              <asp:ListView ID="lvwBillDetail" runat="server" DataSource='<%# Eval("Bills") %>' ItemPlaceholderID="lvwBillsPlaceholder">
                                <LayoutTemplate>
                                    <asp:PlaceHolder ID="lvwBillsPlaceholder" runat="server"></asp:PlaceHolder>
                                </LayoutTemplate>
                                <ItemTemplate>
                                    <tr>
                                        <td>
                                            <asp:Label ID="lblAcct" runat="server" Text='<%#Eval("Acct")%>' />
                                        </td>
                                        <td align="right">
                                            <asp:Label ID="lblAmtBill" runat="server" Text='<%#Bind("Amount", "{0:c}")%>' ></asp:Label>
                                        </td>
                                    </tr>
                                </ItemTemplate>
                            </asp:ListView>
                        </asp:TableCell>
                    </asp:TableRow>
                    <asp:TableFooterRow>
                        <asp:TableCell>
                            Remaining:&nbsp;
                        </asp:TableCell>
                        <asp:TableCell HorizontalAlign="Right">
                            <asp:label ID="lblRemaining" runat="server" Text='<%#Bind("Remaining", "{0:c}")%>' />
                        </asp:TableCell>
                    </asp:TableFooterRow>
                </asp:Table>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:Table ID="tblBillEdits" runat="server" GridLines="None" Width="100%">
                    <asp:TableHeaderRow>
                        <asp:TableCell>Current:&nbsp;</asp:TableCell>
                        <asp:TableCell HorizontalAlign="Right"><asp:Label ID="lblAmount" runat="server" Text='<%#Bind("Amount", "{0:c}")%>' /></asp:TableCell>
                    </asp:TableHeaderRow>
                    <asp:TableRow>
                        <asp:TableCell ColumnSpan="2">
                            <asp:ListView ID="lvwBillDetail" runat="server" DataSource='<%# Eval("Bills") %>' ItemPlaceholderID="lvwBillsPlaceholder">
                                <LayoutTemplate>
                                    <asp:PlaceHolder ID="lvwBillsPlaceholder" runat="server"></asp:PlaceHolder>
                                </LayoutTemplate>
                                <ItemTemplate>
                                    <tr>
                                        <td>
                                            <asp:Label ID="lblAcct" runat="server" Text='<%#Eval("Acct")%>' />
                                        </td>
                                        <td align="right">
                                            <asp:Label ID="lblAmtBill" runat="server" Text='<%#Bind("Amount", "{0:c}")%>' ></asp:Label>
                                        </td>
                                    </tr>
                                </ItemTemplate>
                            </asp:ListView>
                        </asp:TableCell>
                    </asp:TableRow>
                    <asp:TableRow>
                        <asp:TableCell VerticalAlign="Top" >
                            Remaining:&nbsp;
                        </asp:TableCell>
                        <asp:TableCell HorizontalAlign="Right">
                            <asp:label ID="lblRemaining" runat="server" Text='<%#Bind("Remaining", "{0:c}")%>' />
                        </asp:TableCell>
                    </asp:TableRow>
                    <asp:TableRow>
                        <asp:TableCell>
                            <asp:LinkButton ID="lnkAddBill" runat="server" Text="Bill" />
                            <asp:Panel ID="pnlBill" runat="server" style="display:none" CssClass="GeneralPopup" Width="4in">
                                <asp:Table runat="server" ID="tblBillButtons" HorizontalAlign="Center" Width="100%">
                                    <asp:TableRow>
                                        <asp:TableCell>Project</asp:TableCell>
                                        <asp:TableCell><asp:Label ID="lblProjectName" runat="server" /></asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                        <asp:TableCell>Acct</asp:TableCell>
                                        <asp:TableCell>
                                                <asp:DropDownList ID="ddlAct" runat="server" OnSelectedIndexChanged="SelectAcct" />
                                        </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                        <asp:TableCell>Proj Amt. Avail.</asp:TableCell>
                                        <asp:TableCell><asp:Label id="lblProjAmtAvail" runat="server" /></asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                        <asp:TableCell>Acct Amt. Avail</asp:TableCell>
                                        <asp:TableCell><asp:Label ID="lblAcctAmtAvail" runat="server" /></asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                        <asp:TableCell>Amount to Charge:</asp:TableCell>
                                        <asp:TableCell><asp:TextBox ID="txtAmtToCharge" runat="server" /></asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow HorizontalAlign="Center">
                                        <asp:TableCell>
                                            <asp:ImageButton ID="btnOKBill" runat="server" ImageUrl="~/Images/greencheck.gif" OnCommand="PopupButton_Command" CommandName="SelectBill" CommandArgument="Billing" /> 
                                            &nbsp; &nbsp; &nbsp;
                                            <asp:ImageButton ID="btnCxlBill" runat="server" ImageUrl="~/Images/RedX.gif" /> 
                                        </asp:TableCell>
                                    </asp:TableRow>
                                </asp:Table>
                            </asp:Panel>
                            <cc1:ModalPopupExtender ID="mpeBill" runat="server"
                                    TargetControlID="lnkAddBill" PopupControlID="pnlBill"
                                    BackgroundCssClass="modalBackground" CancelControlID="btnCxlBill"
                                    dropshadow="true" PopupDragHandleControlID="pnlBill" />
                        </asp:TableCell>
                        <asp:TableCell>
                            &nbsp;
                        </asp:TableCell>
                    </asp:TableRow>
                </asp:Table>
            </EditItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

The Billing Panel shows up when it should (when lnkAddBill is clicked).

The 'desired behavior' is to get back to the CodeBehind when the user clicks on a different account in the DropDownList so that I can fill in the Label that tells them how much money is left on the account (since they have to enter an amount in the textbox in that panel).

It would appear that the ModalPopupExtender is preventing the DropDownList's OnSelectedIndexChanged event from firing. I have no trouble with getting this to happen with DropDownLists that are in the EditTemplate of a GridViewRow - it just seems that I can't get the event to fire when the DropDownList is in the Panel that the ModalPopupExtender is targeting.

How can I get around this?


Not sure if this is what you're after, but what about including AutoPostBack="true" property to the dropdownlist?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜