[英]Page Load not firing when input control placed in an asp GridView
I have a gridview which displays product information on the index page of my site for a user. 我有一个gridview,它在我的网站的索引页面上为用户显示产品信息。 I want to extend this to allow the user to tick a checkbox if they have reviewed a product.
我想扩展此范围,以允许用户在检查产品时勾选复选框。
However, after adding the check box column into my gridview template, when i try to search multiple times the Page_Load event of my index page stops firing, this causes an issue as some of the events further down the execution tree require the object that is initialised at page load. 但是,在将复选框列添加到我的gridview模板中之后,当我尝试多次搜索索引页的Page_Load事件停止触发时,这会导致问题,因为执行树下的某些事件需要初始化的对象在页面加载时。
The problem seems to be that placing any asp input control inside the gridview is somehow preventing Page_Load from firing before the DataSources OnSelecting and OnSelected and the Grids OnRowDataBound events but i can't see why. 问题似乎是,将任何asp输入控件放置在gridview内都以某种方式阻止了Page_Load在DataSources OnSelecting和OnSelected以及Grids OnRowDataBound事件之前触发,但我不知道为什么。
Here is my sample code, I can't see what I'm doing wrong here. 这是我的示例代码,在这里看不到我做错了什么。
Index.aspx.cs Index.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);
}
Index.aspx Index.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>
Check you master page contentplaceholderid and provide it in content page like this: 检查您的母版页contentplaceholderid并在内容页中提供它,如下所示:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"></asp:Content>
and also check your content page codebehind file name should be same as mention in page directives. 并检查您的内容页面代码背后的文件名应与页面指令中提及的相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.