如何找到控制的ASP.NET GridView控件中的客户端ID? [英] How do I find the Client ID of control within an ASP.NET GridView?

查看:114
本文介绍了如何找到控制的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'不存在于当前上下文存在

The name 'textDateSent' does not exist in the current context

有人知道如何得到这个文本框的客户端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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆