我已经尝试了在这里和其他地方找到的所有建议。我已将页面的 EnableViewState 设置为 true 和 false。我已将网格的 EnableViewState 设置为 true 和 false。我已经尝试在父网格 RowCreated 中注册子网格的事件。我真的很茫然。我该如何进行这项工作?父事件或子事件均未触发。
<%@ Control Language="C#" EnableViewState="False" AutoEventWireup="False" CodeBehind="View.ascx.cs" Inherits="IMS.Modules.CreateMerchandise.View" %>
<asp:GridView ID="gvVariants"
runat="server"
AutoGenerateColumns="False"
CssClass="Grid"
DataKeyNames="ID"
OnRowDataBound="gvVariants_OnRowDataBound"
ShowFooter="True"
EnableViewState="False"
OnRowCreated="gvVariants_OnRowCreated"
OnRowCommand="gvVariants_OnRowCommand">
<Columns>
<asp:TemplateField InsertVisible="False">
<ItemStyle HorizontalAlign="Center" Width="30"/>
<ItemTemplate>
<img alt="" style="cursor: pointer; height: 20px; width: 20px;" src="../images/ManageMerchandise/plus.png"/>
<asp:Panel ID="pnlValues" runat="server" Style="display: none" EnableViewState="False">
<asp:GridView
ID="gvValues"
runat="server"
AutoGenerateColumns="False"
CssClass="ChildGrid"
DataKeyNames="ID"
ShowFooter="True"
EnableViewState="False"
OnRowCommand="gvValues_OnRowCommand">
<Columns>
<asp:TemplateField ItemStyle-Width="15px">
<FooterTemplate>
<asp:Button runat="server" text="Add" ID="btnAddValue" CommandName="AddValue" CommandArgument='<%# Bind("ID") %>'/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField
HeaderText="Value"
InsertVisible="True"
ItemStyle-Width="150px">
<ItemTemplate>
<asp:Label ID="lblValue" runat="server"
Text='<%# Bind("VariantValue") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewValue" runat="server" Width="150"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Use">
<ItemTemplate>
<asp:CheckBox ID="cbUseVariantValue" runat="server"
Enabled="true"/>
</ItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="cbUseNewVariantValue" runat="server"/>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
<FooterTemplate>
<asp:Button runat="server" text="Add" ID="btnAddVariant" CommandName="addVariant" CommandArgument='<%# Bind("ID") %>'/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Variant" InsertVisible="True">
<ItemTemplate>
<asp:Label ID="lblVarietal" runat="server"
Text='<%# Bind("Name") %>'>
</asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="240"/>
<FooterTemplate>
<asp:TextBox ID="NewVariant" runat="server"></asp:TextBox>
</FooterTemplate>
<FooterStyle Wrap="False"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="Use">
<ItemTemplate>
<asp:CheckBox ID="cbUseVariant" runat="server"
Enabled="true"/>
</ItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="cbUseNewVariant" runat="server"/>
</FooterTemplate>
<ItemStyle HorizontalAlign="Center"/>
<FooterStyle HorizontalAlign="Center"/>
</asp:TemplateField>
</Columns>
</asp:GridView>OnLoad:
负载:
protected override void OnLoad(EventArgs e)
{
try
{
base.OnLoad(e);
if (!IsPostBack)
{
gvVariants.DataSource = GetVariantTable();
gvVariants.DataBind();
}
}
catch (Exception exc) //Module failed to load
{
DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
}
}
代码隐藏中的 RowDataBound:
protected void gvVariants_OnRowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
String variantId= gvVariants.DataKeys[e.Row.RowIndex].Value.ToString();
GridView gvValues = e.Row.FindControl("gvValues") as GridView;
using (var ipv = new IMM_ProductVariantValuesController())
{
ipv.Gets(variantId,"IMM_ProductVariants_ID",pWhere: $"and (portal_id=-1 or portal_id={PortalId})");
ipv.LoadDatatable();
gvValues.DataSource = ipv.Datatable;
gvValues.DataBind();
}
}
}
protected void gvVariants_OnRowCommand(Object sender, GridViewCommandEventArgs e)
{
Response.Write("got here");
Response.End();
}