javascript - Get the value from editItem template field of gridview on update button click of gridview -


i have gridview. there 5 columns. roleid, username, password, role, action. columns template fields. in action column have edit button in item template , in same column have update , cancel link button in edit item template. when click on edit button of action column, update , cancel button appear in action column , gridview goes edit mode textboxes in edititem template.

i want validate whatever user enters in textboxes(username) of gridview when edit mode.

i want username column values of clicked row(update button) using javascript when gridview in edit mode textboxes visible.

i tried following not working.

error: 0x800a138f - javascript runtime error: unable property 'cells' of undefined or null reference want values of textbox1(edit item template). textbox1 available in edit mode of gridview when click on editbutton(item template). <%@ page language="c#" autoeventwireup="true" codebehind="gridviewjavascript.aspx.cs" inherits="gridviewjavascript.gridviewjavascript" %>

<!doctype html>  <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title>     <script type="text/javascript">         function gridviewvalidation() {             debugger;             var gridview = document.getelementbyid("gridview1");             var text = gridview.rows[gridview.selectedindex].cells[1].innertext;             alert(text);         }     </script> </head> <body>     <form id="form1" runat="server">     <div>          <asp:gridview id="gridview1" runat="server" autogeneratecolumns="false" backcolor="#deba84" bordercolor="#deba84" borderstyle="none" borderwidth="1px" cellpadding="3" cellspacing="2" datakeynames="roleid" emptydatatext="there no data records display." onrowediting="gridview1_rowediting" onrowupdating="gridview1_rowupdating">             <columns>                 <asp:templatefield headertext="roleid" sortexpression="roleid">                     <edititemtemplate>                         <asp:label id="label1" runat="server" text='<%# eval("roleid") %>'></asp:label>                     </edititemtemplate>                     <itemtemplate>                         <asp:label id="label1" runat="server" text='<%# bind("roleid") %>'></asp:label>                     </itemtemplate>                 </asp:templatefield>                 <asp:templatefield headertext="username" sortexpression="username">                     <edititemtemplate>                         <asp:textbox id="textbox1" runat="server" text='<%# bind("username") %>'></asp:textbox>                     </edititemtemplate>                     <itemtemplate>                         <asp:label id="label2" runat="server" text='<%# bind("username") %>'></asp:label>                     </itemtemplate>                 </asp:templatefield>                 <asp:templatefield headertext="password" sortexpression="password">                     <edititemtemplate>                         <asp:textbox id="textbox2" runat="server" text='<%# bind("password") %>'></asp:textbox>                     </edititemtemplate>                     <itemtemplate>                         <asp:label id="label3" runat="server" text='<%# bind("password") %>'></asp:label>                     </itemtemplate>                 </asp:templatefield>                 <asp:templatefield headertext="role" sortexpression="role">                     <edititemtemplate>                         <asp:textbox id="textbox3" runat="server" text='<%# bind("role") %>'></asp:textbox>                     </edititemtemplate>                     <itemtemplate>                         <asp:label id="label4" runat="server" text='<%# bind("role") %>'></asp:label>                     </itemtemplate>                 </asp:templatefield>                 <asp:templatefield headertext="action">                     <edititemtemplate>                         <asp:linkbutton id="btnupdate" runat="server" commandname="update" onclientclick="return gridviewvalidation()">update</asp:linkbutton>                         &nbsp;                         <asp:linkbutton id="btncancel" runat="server" commandname="cancel">cancel</asp:linkbutton>                     </edititemtemplate>                     <itemtemplate>                         <asp:button id="btnedit" runat="server" commandname="edit" text="edit" />                     </itemtemplate>                 </asp:templatefield>             </columns>             <footerstyle backcolor="#f7dfb5" forecolor="#8c4510" />             <headerstyle backcolor="#a55129" font-bold="true" forecolor="white" />             <pagerstyle forecolor="#8c4510" horizontalalign="center" />             <rowstyle backcolor="#fff7e7" forecolor="#8c4510" />             <selectedrowstyle backcolor="#738a9c" font-bold="true" forecolor="white" />             <sortedascendingcellstyle backcolor="#fff1d4" />             <sortedascendingheaderstyle backcolor="#b95c30" />             <sorteddescendingcellstyle backcolor="#f1e5ce" />             <sorteddescendingheaderstyle backcolor="#93451f" />         </asp:gridview>      </div>     </form> </body> </html> 

i tried following, not working:

<script type="text/javascript">     function gridviewvalidation() {         debugger;         var gridview = document.getelementbyid("textbox1");         alert(gridview.value);     } </script> 

i don't know if mean this?

http://www.martenc.com/2010/12/01/customvalidator-validating-both-empty-text-and-email-address/


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -