如何捕获 Gridview 中 ModalPopupExtender 扩展程序中 DropDownList 的 SelectedIndexChange 事件?
我有一个将数据绑定到通用对象列表的 GridView。每行都有一个必须记入不同帐户的项目。每个项目都有一个属性,它是计费帐户和金额的通用列表 - 该“子列表”显示在嵌入 GridView 列之一的 ListView 中。
当用户单击任何给定行上的“编辑”链接时,在 GridView 的“RowEditing”事件中,我会填充隐藏的弹出面板中的所有字段。当用户单击 ModalPopupExtender 中标识的 LinkButton 时,将显示包含所有适当数据的面板。其中一项是绑定到用户可以从中选择的帐户对象的 .NET 通用列表的 DropDownList。
我的问题是,直到用户单击我设置为“确定”按钮的 ImageButton(使用 OnCommand、CommandName 和 CommandArgument 属性)之后,“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 中的 DropDownList 发生这种情况 - 只是当 DropDownList 位于 ModalPopupExtender 所针对的面板中时,我似乎无法触发该事件。
我该如何解决这个问题?
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: </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>
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这是否是您想要的,但是将 AutoPostBack="true" 属性包含到下拉列表中怎么样?
Not sure if this is what you're after, but what about including AutoPostBack="true" property to the dropdownlist?