c# - how to get textbox value in gridview using javascript -
i want textbox value within gridview using javascript. can't find out value. asp.net page.how can "txtgridname" value update button onclientclick?
asp.net code here :
<columns> <asp:templatefield headertext="s.no"> <itemtemplate> <%#container.dataitemindex+1 %> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="unit std"> <edititemtemplate> <%--<asp:textbox id="txtloceditname" width="100%" runat="server" text='<%#(eval("loc_name").tostring()) %>' />--%> <asp:dropdownlist id="drpgridunitstd" runat="server" text='<%#(eval("uom_standard").tostring()) %>'> <asp:listitem text="a" value="a"></asp:listitem> <asp:listitem text="i" value="i"></asp:listitem> </asp:dropdownlist> </edititemtemplate> <itemtemplate> <asp:label id="lbllocation" runat="server" text='<%#(eval("uom_standard").tostring())%>' /> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="unit name"> <edititemtemplate> <asp:textbox id="txtgridname" width="100%" runat="server" text='<%#(eval("uom_ts_unit").tostring()) %>' /> </edititemtemplate> <itemtemplate> <asp:label id="lblgridname" runat="server" text='<%#(eval("uom_ts_unit").tostring()) %>' /> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="dimension-1"> <edititemtemplate> <asp:textbox id="txtgriddim1" width="100%" runat="server" text='<%#(eval("uom_dimension_1").tostring()) %>' /> </edititemtemplate> <itemtemplate> <asp:label id="lblgriddim1" runat="server" text='<%#(eval("uom_dimension_1").tostring())%>' /> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="dimension-2"> <edititemtemplate> <asp:textbox id="txtgriddim2" width="100%" runat="server" text='<%#(eval("uom_dimension_2").tostring()) %>' /> </edititemtemplate> <itemtemplate> <asp:label id="lblgriddim2" runat="server" text='<%#(eval("uom_dimension_2").tostring())%>' /> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="dimension-3"> <edititemtemplate> <asp:textbox id="txtgriddim3" width="100%" runat="server" text='<%#(eval("uom_dimension_3").tostring()) %>' /> </edititemtemplate> <itemtemplate> <asp:label id="lblgriddim3" runat="server" text='<%#(eval("uom_dimension_3").tostring())%>' /> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="dimension-4"> <edititemtemplate> <asp:textbox id="txtgriddim4" width="100%" runat="server" text='<%#(eval("uom_dimension_4").tostring()) %>' /> </edititemtemplate> <itemtemplate> <asp:label id="lblgriddim4" runat="server" text='<%#(eval("uom_dimension_4").tostring())%>' /> </itemtemplate> </asp:templatefield> <asp:templatefield headerstyle-cssclass="hidegridcolumn" itemstyle-cssclass="hidegridcolumn"> <itemtemplate> <asp:hiddenfield id="hdnunit_id" value='<%#(eval("unit_id").tostring())%>' runat="server" /> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="options"> <edititemtemplate> <asp:imagebutton id="imgbtnupdate" commandname="update" runat="server" imageurl="~/common/icons/save-icon.png" tooltip="update" height="15px" width="15px" onclientclick="return update();"/> <asp:imagebutton id="imgbtncancel" runat="server" commandname="cancel" imageurl="~/common/icons/delete-icon.png" tooltip="cancel" height="15px" width="15px" /> </edititemtemplate> <itemtemplate> <asp:imagebutton id="imgbtnedit" commandname="edit" runat="server" imageurl="~/common/icons/edit.png" tooltip="edit" height="15px" width="15px" /> <asp:imagebutton id="imgbtndelete" commandname="delete" runat="server" imageurl="~/common/icons/delete.png" tooltip="delete" height="15px" width="15px" onclientclick="return del();" /> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
javascript code follows :
function update() { var grid1 = document.getelementbyid("<%= gvunit.clientid %>"); (i = 1; < grid1.rows.length ; i++) { var cellvalue = grid1.rows[i].cells[1].value; alert(cellvalue); } }
the problem client id following:
ct100_contentplaceholder_gridid_rowid_rowindex_textboxid
something that. , can't uniquely identified. since grid works 1 edit though, find easier. since aren't using jquery, it's little more complicated. maybe if add cssclass="gridtextbox"
textbox control , use getelementsbyclassname:
var tb = document.getelementsbyclassname('gridtextbox');
Comments
Post a Comment