我有一个 gridview,它在我的网站的索引页面上为用户显示产品信息。我想扩展它以允许用户在他们审查过产品时勾选复选框。
但是,在将复选框列添加到我的 gridview 模板后,当我尝试多次搜索时,我的索引页面的 Page_Load 事件停止触发,这会导致问题,因为执行树下方的一些事件需要初始化的对象在页面加载。
问题似乎是在 gridview 中放置任何 asp 输入控件会以某种方式阻止 Page_Load 在 DataSources OnSelecting 和 OnSelected 以及 Grids OnRowDataBound 事件之前触发,但我不明白为什么。
这是我的示例代码,我看不出我在这里做错了什么。
索引.aspx.cs
private ProductSearch productSearch
protected void Page_Load(object sender, EventArgs e)
{
productSearch = new ProductSearch(GetSearchParameters());
productSearch.PageLoad()
}
protected void ProductsSelecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
e.InputParameters["searchParams"] = productSearch.GetSearchParams();
}
protected void ProductsSelected(object sender, ObjectDataSourceStatusEventArgs e)
{
productSearch.SetExportToCsvButton();
}
protected void ProductsPageIndexChanging(object sender, GridViewPageEventArgs e)
{
dgProducts.PageIndex = e.NewPageIndex;
}
protected void ProductsOnRowDataBound(object sender, GridViewRowEventArgs e)
{
productSearch.ProductsRowDataBound(e.Row);
}
索引.aspx
<%@ Page Language="C#" MasterPageFile="~/Admin/AdminMaster.master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="Web.Admin.Index" %>
<asp:Content ContentPlaceHolderID="DataFrame" runat="server">
<asp:GridView ID="dgProducts" runat="server" AllowPaging="True" AllowSorting="True" EnableViewState="False"
AutoGenerateColumns="False" DataSourceID="dsProducts" PagerSettings-Position="TopAndBottom" DataKeyNames="ProductNo, KitID"
OnPageIndexChanging="ProductsPageIndexChanging" OnRowDataBound="ProductsOnRowDataBound"
EmptyDataText="There are no products matching your search." meta:resourcekey="dgProducts" onrowcreated="ProductsRowCreated">
<HeaderStyle Font-Size="Small" />
<Columns>
<asp:TemplateField HeaderText="Reviewed">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkReviewed" class="reviewedCheckbox" Checked="False" />
</ItemTemplate>
</asp:TemplateField>
</Columns
</asp:GridView>
<asp:ObjectDataSource ID="dsProducts" runat="server" EnablePaging="True" SelectMethod="ProductAndKitSearchByParams"
TypeName="ProductSearchController.ProductSearch" onselecting="ProductsSelecting" SortParameterName="SortParameter"
SelectCountMethod="SelectVirtualCount" OnSelected="ProductsSelected">
<SelectParameters>
<asp:Parameter ConvertEmptyStringToNull="true" DefaultValue="" Name="searchParams" Type="Object" />
</SelectParameters>
</asp:ObjectDataSource>
</asp:Content>