本文介绍了如何找到控制的ASP.NET GridView控件中的客户端ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ASP:GridView控件,其中包含一个ASP:文本框一个TemplateField内。我想获得它在JavaScript中使用的ID。事情是这样的:
I have a asp:GridView which contains a asp:TextBox within a TemplateField. I would like to obtain it's ID for use in javascript. Something like this:
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="textDateSent" runat="server" />
<input type="button" value='Today'
onclick="setToday('<%# textDateSent.ClientID %>');" />
</ItemTemplate>
</asp:TemplateField>
但是,当我编译,我得到一个错误:
But when I compile, I get an error:
名称'textDateSent'不存在于当前上下文存在
有人知道如何得到这个文本框的客户端ID?
Anybody know how to get the client ID of this TextBox?
推荐答案
试试这个:
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="textDateSent" runat="server">
</asp:TextBox>
<input type="button" value='Today' onclick="setToday('<%# ((GridViewRow)Container).FindControl("textDateSent").ClientID %>');" />
</ItemTemplate>
</asp:TemplateField>
这篇关于如何找到控制的ASP.NET GridView控件中的客户端ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!