本文介绍了如何在 ASP.NET GridView 中找到控件的客户端 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 asp:GridView,它在 TemplateField 中包含一个 asp:TextBox.我想获取它的 ID 以在 javascript 中使用.像这样:
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"在当前上下文中不存在
有人知道如何获取这个TextBox的客户端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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!