本文介绍了动态获取文本框的ID并分配给变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I have a Grid Under the ContentPlaceholder here the grid is Dynamic where it rows will be increasing accordingly to the Values i pass from Database. On pageload if my Grid contains 5rows for example, i want to get the ID of all the Textbox which is in Grid Dynamically and assign it to the Variable.. How to do it.. When i Run the page and checked view source from browser i got my Textbox name like this "ctl00_MainContent_gvtemp_ctl00_ctl04_txtDescription" "ctl00_MainContent_gvtemp_ctl00_ctl06_txtDescription" "ctl00_MainContent_gvtemp_ctl00_ctl08_txtDescription" "ctl00_MainContent_gvtemp_ctl00_ctl10_txtDescription" "ctl00_MainContent_gvtemp_ctl00_ctl12_txtDescription" I need to Pass those Id to Var ids like below.. var ids = ["ctl00_MainContent_gvtemp_ctl00_ctl04_txtDescription", "ctl00_MainContent_gvtemp_ctl00_ctl06_txtDescription", "ctl00_MainContent_gvtemp_ctl00_ctl08_txtDescription", "ctl00_MainContent_gvtemp_ctl00_ctl10_txtDescription", "ctl00_MainContent_gvtemp_ctl00_ctl12_txtDescription", "ctl00_MainContent_gvtemp_ctl00_ctl14_txtDescription", "ctl00_MainContent_gvtemp_ctl00_ctl16_txtDescription"]; Here my Grid Coding: <telerik:RadGrid ID="gvtemp" AllowSorting="false" AllowPaging="false" runat="server" CssClass="grid tBorder" ShowFooter="false" AllowMultiRowSelection="false" AllowMultiRowEdit="false" AllowFilteringByColumn="false" CellSpacing="0" CellPadding="0" AutoGenerateColumns="False" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Center" AlternatingItemStyle-HorizontalAlign="Left" HorizontalAlign="Center"> <MasterTableView> <Columns> <telerik:GridTemplateColumn HeaderText="Brand" ItemStyle-Width="3%"> <ItemTemplate> <asp:Label ID="lblBrand" runat="server" Text='<%# Bind("BRAND") %>' /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn HeaderText="Description" ItemStyle-Width="50%" UniqueName="Description"> <ItemTemplate> <asp:TextBox ID="txtDescription" runat="server" Text='<%# Bind("DESCRIPTION") %>' Height="75px" TextMode="MultiLine" Width="100%"/> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> <EditFormSettings> <EditColumn FilterControlAltText="Filter EditCommandColumn column"> </EditColumn> </EditFormSettings> </MasterTableView> <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_"> </HeaderContextMenu> </telerik:RadGrid>
推荐答案
我试过并获得文本框的ID,如 var masterTable = I tried and got the ID of the textbox like var masterTable =
find(<%= gvtemp。 ClientID%>)。get_masterTableView(); var row = masterTable.get_dataItems(); var ids = new Array(row); for(var i = 0;我< row.length; i ++){ var rowid = masterTable.get_dataItems()[i] .findElement(txtDescription)。id; ids [i] = rowid; } find("<%= gvtemp.ClientID %>").get_masterTableView(); var row = masterTable.get_dataItems(); var ids = new Array(row); for (var i = 0; i < row.length; i++) { var rowid = masterTable.get_dataItems()[i].findElement("txtDescription").id; ids[i] = rowid; }
更多推荐
动态获取文本框的ID并分配给变量
发布评论