我在使用另一个gridview
中的gridview的rowcommand时遇到问题问题在于,当我向第二个gridview添加一个事件时,该事件不会运行在另一个gridview的项模板中,我怎么能让它工作?
我的代码是:
<asp:ToolkitScriptManager runat="server" ID="MainScriptManager" />
<asp:SqlDataSource ID="sqlDsSubCategories" runat="server"
ConnectionString="<%$ ConnectionStrings:Scan_SystemConnectionString %>"
SelectCommand="SP_Categoria" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter DefaultValue="01" Name="div" SessionField="DivNom"
Type="String" />
<asp:SessionParameter DefaultValue="04" Name="mes" SessionField="mes"
Type="String" />
<asp:SessionParameter DefaultValue="2013" Name="year" SessionField="year"
Type="String" />
<asp:SessionParameter DefaultValue="042013" Name="fecha" SessionField="fecha"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:UpdatePanel ID="pnlUpdate" runat="server">
<ContentTemplate>
<asp:GridView Width="100%" ID="gvSubCategories"
AutoGenerateColumns="False"
GridLines="None"
CssClass="mGrid"
DataSourceID="sqlDsSubCategories" runat="server"
ShowHeader="False"
OnRowCreated="gvSubCategories_RowCreated"
DataKeyNames="CG_CATEGORIA">
<Columns>
<asp:TemplateField>
<ItemStyle Width="200px" />
<ItemTemplate>
<asp:Panel ID="pnlSubCategories" runat="server">
<asp:Image ID="imgCollapsible"
Style="margin-right: 5px;" runat="server" />
<span style="font-weight:bold">
SubCategory: <%# Eval("CG_CATEGORIA")%> | Total: $<%# Eval("dist_amt")%></span></asp:Panel>
<asp:SqlDataSource ID="sqlDsProducts" runat="server"
ConnectionString="<%$ ConnectionStrings:Scan_SystemConnectionString %>"
SelectCommand="SP_VoucherPorDiv" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter DefaultValue="01" Name="div" SessionField="DivNom"
Type="String" />
<asp:SessionParameter DefaultValue="04" Name="mes" SessionField="mes"
Type="String" />
<asp:SessionParameter DefaultValue="2013" Name="year" SessionField="year"
Type="String" />
<asp:SessionParameter DefaultValue="042013" Name="fecha" SessionField="fecha"
Type="String" />
<asp:Parameter DefaultValue="" Name="cat" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Panel ID="pnlProducts" runat="server"
Width="75%"
Style="margin-left:20px;margin-right:20px;
height:0px;overflow: hidden;">
<asp:GridView Width="90%" AutoGenerateColumns="False"
CssClass="mGrid" ID="gvProducts" HorizontalAlign="Center" PagerStyle-HorizontalAlign="Center" RowStyle-HorizontalAlign="Center"
DataSourceID="sqlDsProducts"
runat="server" EnableViewState="False"
GridLines="None"
AlternatingRowStyle-CssClass="alt">
<Columns>
<asp:BoundField HeaderText="Voucher"
DataField="vchr_or_chk_no"/>
<asp:BoundField
HeaderText="Reference"
DataField="reference"/>
<asp:BoundField
HeaderText="Quantity"
DataField="dist_amt"/>
<asp:TemplateField HeaderText="Consult">
<ItemTemplate>
<asp:LinkButton ID="verpdf" runat="server" CommandName="Select">View</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
<asp:CollapsiblePanelExtender
ID="ctlCollapsiblePanel"
runat="Server"
TargetControlID="pnlProducts"
CollapsedSize="0" Collapsed="True"
ExpandControlID="pnlSubCategories"
CollapseControlID="pnlSubCategories"
AutoCollapse="False" AutoExpand="False"
ScrollContents="false"
ImageControlID="imgCollapsible"
ExpandedImage="~/collapse.png"
CollapsedImage="~/expand.png"
ExpandDirection="Vertical" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Protected Sub gvSubCategories_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvSubCategories.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ctrl As SqlDataSource = TryCast(e.Row.FindControl("sqlDsProducts"), SqlDataSource)
If ctrl IsNot Nothing AndAlso e.Row.DataItem IsNot Nothing Then
ctrl.SelectParameters("cat").DefaultValue = gvSubCategories.DataKeys(e.Row.RowIndex).Value.ToString()
End If
End If
End Sub
答案 0 :(得分:0)
你必须连接子GridView的RowCommand;您可以在父GridView的RowCreated事件中编写此代码,因为此事件在Page_Load之后和处理回发事件之前触发。
例如在c#:
中protected void parentGrid_RowCreated(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
childGrid = e.Row.FindControl("childGrid") as GridView;
childGrid.RowCommand += new GridViewCommandEventHandler(childGrid_RowCommand);
}
}