我有一個GridView是數據綁定到一個通用的對象列表。每一行都有一個項目,必須向各種賬戶開具賬單。每個項目都有一個屬性,這是一個通用的賬單和金額清單 - 這個「子列表」顯示在GridView的一列中嵌入的ListView中。如何捕獲Gridview中ModalPopupExtender擴展器中的DropDownList的SelectedIndexChange事件?
當用戶單擊任何給定行上的「編輯」鏈接時,在GridView的「RowEditing」事件中,我填充隱藏彈出式面板中的所有字段。當用戶單擊ModalPopupExtender中標識的LinkButton時,該面板將顯示所有適當的數據。一個項目是綁定到用戶可以從中選擇的.NET通用的帳戶對象列表的DropDownList。
我的問題是,直到用戶點擊了我設置爲「OK」按鈕(使用OnCommand,CommandName和CommandArgument屬性)的ImageButton之後,「OnSelectedIndexChanged」事件纔會觸發。
這裏是在顯示代碼是如何嘗試:
<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: </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:TableFooterRow>
<asp:TableCell>
Remaining:
</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: </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:
</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" />
<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>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
付費面板顯示了應(被點擊時lnkAddBill),當它。
'所需的行爲'是當用戶點擊DropDownList中的不同帳戶時返回CodeBehind,以便我可以填寫標籤,告訴他們帳戶上有多少錢(因爲他們有在該面板的文本框中輸入金額)。
這似乎是ModalPopupExtender阻止DropDownList的OnSelectedIndexChanged事件發射。我在使用GridViewRow的EditTemplate中的DropDownLists時沒有遇到這種情況 - 當DropDownList位於ModalPopupExtender所針對的面板中時,我似乎無法觸發該事件。
我該如何解決這個問題?
我的問題(與該解決方案)是在找到DropDownList,以便我可以得到結果 - 必須得到正確的級聯Control.FindControl(「nextcontrol」)語句序列。現在我的問題是讓彈出面板更新DISPLAY在DropDownList索引更改時剛加載的信息。我想我必須更改ModalPopupExtender引用UpdatePanel的面板。 – David 2011-03-09 15:43:18