本文介绍了动态获取文本框的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并分配给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!