vb.net - Gridview inside another Gridview using item template -


i have problem using rowcommand of gridview in gridview

the problem when add event second gridview in item template of gridview event don't run so, how can make work?

my code is:

<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 object, byval e system.web.ui.webcontrols.gridviewroweventargs) handles gvsubcategories.rowcreated         if e.row.rowtype = datacontrolrowtype.datarow             dim ctrl sqldatasource = trycast(e.row.findcontrol("sqldsproducts"), sqldatasource)             if ctrl isnot nothing andalso e.row.dataitem isnot nothing                 ctrl.selectparameters("cat").defaultvalue = gvsubcategories.datakeys(e.row.rowindex).value.tostring()             end if         end if      end sub 

you have wire rowcommand of child gridview; can write code inside rowcreated event of parent gridview because event fired after page_load , before handling post event.

for example in c#:

protected void parentgrid_rowcreated(object sender, gridviewroweventargs e)      {         if (e.row.rowtype == datacontrolrowtype.datarow)         {             childgrid = e.row.findcontrol("childgrid") gridview;             childgrid.rowcommand += new gridviewcommandeventhandler(childgrid_rowcommand);         }     } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -