我有服务器控件,例如在另一个gridview的模板字段中带有gridview的弹出窗口:
<asp:TemplateField HeaderText="Actions">
<ItemTemplate>
<asp:Button ID="viewHoursButton" runat="server" Text="View Hours" OnClick="viewHoursButton_OnClick" />
<ajaxToolkit:ModalPopupExtender ID="viewHoursPopup" runat="server"
TargetControlID="viewHoursButton"
PopupControlID="viewHoursPanel"
CancelControlID="closeInfoPanelButton2"
DropShadow="true">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="viewHoursPanel" runat="server" CssClass="infoPanel">
<asp:Button ID="closeInfoPanelButton2" runat="server" Text="X" CssClass="closeInfoPanelButton" />
<asp:Label ID="viewHoursLabel" runat="server" Text="Label"></asp:Label>
<asp:GridView ID="viewHoursGridView" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataSourceID="SqlDataSource6" DataKeyNames="NonScrumStoryId,PK_DailyTaskHours"
BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
CellPadding="3" CellSpacing="2" Width="94%" OnRowDeleting="viewHoursGridView_OnRowDeleting"
OnRowDataBound="viewHoursGridView_OnRowDataBound" CssClass="centerGridView">
<Columns>
<asp:BoundField DataField="ActivityDate" HeaderText="Activity Date" SortExpression="ActivityDate"
DataFormatString="{0:MM/dd/yyyy}" />
<asp:BoundField DataField="Hours" HeaderText="Hours" SortExpression="Hours" />
<asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
<asp:BoundField DataField="CreateDate" HeaderText="Created Date" SortExpression="CreateDate"
Visible="false" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#7fc041" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
SelectCommand="
SELECT [DailyTaskHours].[PK_DailyTaskHours]
,[DailyTaskHours].[NonScrumStoryId]
,[DailyTaskHours].[Hours]
,[DailyTaskHours].[Notes]
,[DailyTaskHours].[ActivityDate]
,[DailyTaskHours].[CreateDate]
FROM [NonScrumStory]
,[DailyTaskHours]
WHERE [DailyTaskHours].[NonScrumStoryId] = @nonScrumStoryId
AND [NonScrumStory].[PK_NonScrumStory] = @nonScrumStoryId
ORDER BY [ActivityDate] DESC
"
DeleteCommand="
DELETE
FROM [DailyTaskHours]
WHERE ([PK_DailyTaskHours] = @setDailyPKDeleteParam)
">
<SelectParameters>
<asp:QueryStringParameter Name="nonScrumStoryId" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:QueryStringParameter Name="setDailyPKDeleteParam" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>
</asp:Panel>
<asp:Button ID="addHoursButton" runat="server" Text="Add Hours" OnClick="addHoursButton_OnClick" />
<asp:Button ID="editButton" runat="server" Text="Edit" OnClick="editButton_OnClick" />
<asp:Button ID="deleteButton" runat="server" Text="Delete" OnClick="deleteButton_OnClick" />
</ItemTemplate>
</asp:TemplateField>
我无法将它们移出gridview,因为调用弹出窗口必须正常工作。
但是我后面的代码无法识别 ItemTemplate 中的某些 ID:
protected void viewHoursButton_OnClick(object sender, EventArgs e)
{
viewHoursPopup.Show();
viewHoursGridView.DataBind();
}
例如,即使按钮位于 ItemTemplate 内,_OnClick 方法也可以工作,但无法识别两个方法调用:
我该如何解决这个问题?