简体   繁体   English

将gridview模板字段文本框ID传递给javascript函数

[英]Pass gridview template field text box id to a javascript function

I have a ASP GridView in my webpage. 我的网页中有一个ASP GridView。

I have two template fields 1 textbox and 1 hyperlink. 我有两个模板字段1文本框和1超链接。

If i click the hyperlink on that particular row I need to pass the corresponding textbox id in that particular row of gridview. 如果我单击该特定行上的超链接,则需要在gridview的该特定行中传递相应的文本框ID。

<asp:TemplateField HeaderText="Input">
    <ItemTemplate>
        <asp:TextBox ID="txtInput" Text='<%# Eval("Input") %>' Width="200px" Height="70px" runat="server" TextMode="MultiLine"></asp:TextBox>
    </ItemTemplate>
    <ItemStyle Width="20px" Height="30px" BorderStyle="Solid" Font-Size="12px" HorizontalAlign="Left"
    VerticalAlign="Middle" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Verify">
    <ItemTemplate>
        <a href="#" id="lnkView" onclick="GetResults('#<%= txtInput.ClientID %>')">
        <%#Eval("Verify")%>
        </a>
    </ItemTemplate>
    <ItemStyle Width="203px" Height="15px" BorderStyle="Solid" BorderWidth="1px" Font-Size="12px" HorizontalAlign="Left"
    VerticalAlign="Middle" />
</asp:TemplateField>

I tried the below code but am getting error as name 'txtInput' does not exist in current context. 我尝试了下面的代码,但由于当前上下文中不存在名称“ txtInput”而出现错误。

Javascript function Javascript功能

function GetResults(id) {

//My code using this textbox id

}

Please help on how to pass the text box id to javascript function on click of the hyperlink 单击超链接时,请帮助如何将文本框ID传递给javascript函数

Something like this might work (untested). 这样的事情可能会起作用(未经测试)。

Following line, remove the # sign. 在下面的行中,删除#号。

<a href="#" id="lnkView" onclick="GetResults('<%= txtInput.ClientID %>')">

Then your javascript: 然后你的JavaScript:

function GetResults(id) {

var ctrlId = "[id$=" + id + "]"
var inputVal = $(ctrlId).val()

// do work

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM