In short, a Web control with an ID of txtFirstName can get rendered into an HTML element with a client-side id like "ctl00_MainContent_txtFirstName". And same is true for ASP.NET GridView.
Suppose, there is textbox and label control in gridview.
<ItemTemplate>And when you run this, this is rendered as below.
<asp:TextBox ID="txtID" runat="server" />
<asp:Label ID="lblID" runat="server" />
</ItemTemplate>
<input name="gdRows$ctl02$txtID" type="text" id="gdRows_ctl02_txtID" />As you notice, the ID of the control is changed. It is no more "txtID" or "lblID". Gridview ID and control number is added as prefix. So now how do you select these controls?
<span id="gdRows_ctl02_lblTest"></span>
Related Post:
- Download ASP.NET GridView & jQuery Tips and Tricks eBook
- Common jQuery Mistakes
- ASP.NET GridView and jQuery
$('#<%=gdRows.ClientID %>').find('span[id$="lblID"]').text('Your text.');To select particular label control out of all the labels which ends with "lblID".
var $arrL = $('#<%=gdRows.ClientID %>').find('span[id$="lblID"]');Similarly, you can also find textbox. To select all textbox which has ID as "txtID".
var $lbl = $arrL[0];
$($lbl).text('Your text...');
$('#<%=gdRows.ClientID %>').find('input:text[id$="txtID"]').val('Your value.');To select particular textbox control out of all the textboxes which ends with "lblID".
var $arrT = $('#<%=gdRows.ClientID %>').find('input:text[id$="txtID"]');Feel free to contact me for any help related to jQuery, I will gladly help you.
var $txt = $arrT[0];
$($txt).val('text...');
No comments:
Post a Comment