c# - Uniquely identify controls in nested gridview for validation -


i have nested grid. validate dropdown control within child grid when user adds record. in nested grid, control ids not unique. if have 2 parent rows , nested grid under each parent child grid controls have same id. when validate, validation checking of nested grids , not 1 trying add to.

this markup:

 <asp:gridview id="groupgridview" runat="server" autogeneratecolumns="false"              caption="group information" captionalign="top" cssclass="grid"              showfooter="true" datakeynames="groupid">             <columns>                 <asp:templatefield>                     <itemtemplate>                         <a href="javascript:divexpandcollapse('div<%# eval("groupid")%>');">                         <img id="imgdiv<%# eval("groupid")%>" width="25px" border="0" src="images/plus.png" /> </a>                      </itemtemplate>                 </asp:templatefield>                 <asp:templatefield headertext="groupid">                     <itemtemplate>                         <asp:label id="uggvlblgroupid" runat="server" text='<%# bind("groupid") %>'></asp:label>                     </itemtemplate>                 </asp:templatefield>                 <asp:templatefield headertext="group name">                     <itemtemplate>                         <asp:label id="uggvlblgroupname" runat="server" text='<%# bind("groupname") %>'></asp:label>                     </itemtemplate>                     </asp:templatefield>                 <asp:templatefield headertext="action" itemstyle-wrap="false" itemstyle-horizontalalign="center">                     <itemtemplate>                         <asp:button id="uggvdeletebutton" runat="server" causesvalidation="false" commandname="delete"                                          text="delete" cssclass="gridactionbutton"  onclientclick="return confirm('are sure want delete group information?')" >                         </asp:button>                         <tr><td colspan="100%">                           <div id="div<%# eval("groupid") %>" style="display:none">                             <asp:gridview id="groupmembergridview" runat="server" autogeneratecolumns="false"                                    cssclass="grid" showfooter="true">                                 <columns>                                     <asp:templatefield headertext="memberid">                                         <itemtemplate>                                             <asp:label id="mggvlblmemberid" runat="server" text='<%# bind("memberid") %>'></asp:label>                                         </itemtemplate>                                     </asp:templatefield>                                     <asp:templatefield headertext="member name" itemstyle-wrap="false">                                          <itemtemplate>                                             <asp:label id="mggvlblmembername" runat="server" text='<%# bind("membername") %>'></asp:label>                                         </itemtemplate>                                                        <footertemplate>                                             <asp:dropdownlist id="mggvddlmembername" runat="server" clientidmode="static"                                                 class="chosen-single" data-placeholder="choose member…">                                             </asp:dropdownlist>                                             <asp:requiredfieldvalidator id="reqvalueddlmemberinsert" runat="server" initialvalue="0"                                                     controltovalidate="mggvddlmembername" validationgroup="'<%# "insertgroupmembervalidation_" + eval("groupid") %>'                                                      errormessage="selection required." cssclass="message-error-dropdown">                                             </asp:requiredfieldvalidator>                                                                                </footertemplate>                                     </asp:templatefield>                                                                     <asp:templatefield headertext="action" itemstyle-wrap="false" itemstyle-horizontalalign="center">                                                                    <footertemplate>                                             <asp:button id="mggvaddbutton" runat="server" commandname="add" text="add member" width="90%"                                                   cssclass="gridactionbutton" validationgroup='<%# "insertgroupmembervalidation_" + eval("groupid") %>'> causesvalidation="true">                                             </asp:button>                                         </footertemplate>                                     </asp:templatefield>                                 </columns>                             </asp:gridview>                         </div>                     </itemtemplate>                                  <footertemplate>                         <asp:button id="uggvaddbutton" runat="server" commandname="add" text="add group" width="90%" causesvalidation="true"                                          cssclass="gridactionbutton" validationgroup="insertgroupnamevalidation"                         </asp:button>                     </footertemplate>                     </asp:templatefield>             </columns>         </asp:gridview> 

regardless of 'add member' button click, validation triggered of nested grids because validation groups not unique.

how can uniquely identify validationgroup each nested grid?

thanks.

update validationgroup identifier works when adding member first nested group not subsequent nested grids. seems still going thru of nested grids , not 1 'add' button clicked.

//access validators , buttons         requiredfieldvalidator requiredfieldvalidator1 = (requiredfieldvalidator)e.row.findcontrol("requiredfieldvalidator1");         requiredfieldvalidator requiredfieldvalidator2 = (requiredfieldvalidator)e.row.findcontrol("requiredfieldvalidator2");         requiredfieldvalidator requiredfieldvalidator3 = (requiredfieldvalidator)e.row.findcontrol("requiredfieldvalidator3");         button button = (button)e.row.findcontrol("button1");          //assign validation group controls.         requiredfieldvalidator1.validationgroup = "gridview1" + e.row.rowindex.tostring();         requiredfieldvalidator2.validationgroup = "gridview1" + e.row.rowindex.tostring();         requiredfieldvalidator3.validationgroup = "gridview1" + e.row.rowindex.tostring();         button.validationgroup = "gridview1" + e.row.rowindex.tostring(); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -