c# - Row index from hierarchical gridview -


i have gridview structure -

  <asp:gridview id="gvtest" runat="server" autogeneratecolumns="false"          width="100%">         <columns>             <asp:templatefield headertext="rule name" itemstyle-verticalalign="top">                 <itemtemplate>                     <asp:label id="lblrulename" runat="server" text='<%# bind("rulename") %>'></asp:label>                 </itemtemplate>             </asp:templatefield>               <asp:templatefield headertext="source" itemstyle-verticalalign="top">                 <itemtemplate>                     <asp:gridview id="gvsource" runat="server" showheader="false" autogeneratecolumns="false">                      <columns>                             <asp:templatefield>                                 <itemtemplate>                                  <asp:imagebutton id="imgexpandsource" runat="server" imageurl="~/plus.png" onclick="imgexpandsource_click"/>                                   <asp:imagebutton id="imgexpandsource1" runat="server" imageurl="~/minus.png" onclick="imgexpandsource1_click" visible="false"/>                                     <asp:label id="lblsourceobjname" runat="server" text='<%# bind("sourceobjname") %>'></asp:label>                                                                             <asp:gridview id="gvsourceobj" runat="server" showheader="false" visible="false">                                     </asp:gridview>                                 </itemtemplate>                             </asp:templatefield>                         </columns>                     </asp:gridview>                 </itemtemplate>             </asp:templatefield>               <asp:templatefield headertext="destination" itemstyle-verticalalign="top">                 <itemtemplate>                     <asp:gridview id="gvdestination" runat="server" showheader="false" autogeneratecolumns="false">                         <columns>                             <asp:templatefield>                                 <itemtemplate>                                  <asp:imagebutton id="imgexpand" runat="server" imageurl="~/plus.png" onclick="imgexpand_click"/>                                  <asp:imagebutton id="imgexpand1" runat="server" imageurl="~/minus.png" onclick="imgexpand1_click" visible="false"/>                                     <asp:label id="lbldestobjname" runat="server" text='<%# bind("destobjname") %>'></asp:label>                                                                            <asp:gridview id="gvdestobj" runat="server" showheader="false" visible="false">                                     </asp:gridview>                                 </itemtemplate>                             </asp:templatefield>                         </columns>                     </asp:gridview>                 </itemtemplate>             </asp:templatefield>               <asp:templatefield headertext="service group" itemstyle-verticalalign="top">                 <itemtemplate>                     <asp:gridview id="gvserviceobject" runat="server" showheader="false">                     </asp:gridview>                 </itemtemplate>             </asp:templatefield>         </columns>     </asp:gridview>   

now want row index of gvtest gridview on imgexpandsource link button's click event. tried code -

 protected void imgexpandsource_click(object sender, imageclickeventargs e)     {          imagebutton imgexpandsource = sender imagebutton;         gridviewrow gvrow = (gridviewrow)imgexpandsource.namingcontainer;         int x = gvrow.rowindex;     } 

but giving me gvsource gridviews row index. how can gvtest gridviews row index. please 1 me.

thanks gulrej

you need add more levels right naming contrainer:

protected void imgexpandsource_click(object sender, imageclickeventargs e) {      imagebutton imgexpandsource = sender imagebutton;     gridviewrow gvrow = (gridviewrow)imgexpandsource                              // gridviewrowrow of gvsource                              .namingcontainer                              // gvsource                              .namingcontainer                              // gridviewrow of gvtest                              .namingcontainer;     int x = gvrow.rowindex; } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -