最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - How to get the gridview textbox control ID in javascript? - Stack Overflow

programmeradmin3浏览0评论

I have ASP.NET Gridview and Textbox control in it. Now I want to get the Textbox ID in java script. I had already referred this question in stack overflow but I couldn't get the exact answer.

My Gridview Template Code is

<asp:TemplateField HeaderText="Amt Recieve Now" ControlStyle-Width="100">
   <ItemTemplate>
    <asp:TextBox ID="txtAmountReceiveNow" runat="server" CssClass="textboxRight"
        AutoPostBack="true" OnFocus= "GVtxtAmount()"
        OnTextChanged="txtAmountReceiveNow_TextChange" 
                Text='<%#Eval("AMOUNT_RECEIVE_NOW")%>'>
     </asp:TextBox>
   </ItemTemplate>
</asp:TemplateField>

and Javascript code is as follows :

 function GVtxtAmount() {
    var txtAmountReceive = document.getElementById(
                  '<%= ((GVMaintainReceiptMaster)Container)
                         .FindControl("txtAmountReceiveNow").ClientID %>');
    var selection = txtAmountReceive.value.indexOf(".");
    alert(selection);
 };

GVMaintainReceiptMaster is ID of GridView

Help me to overe this problem.

I have ASP.NET Gridview and Textbox control in it. Now I want to get the Textbox ID in java script. I had already referred this question in stack overflow but I couldn't get the exact answer.

My Gridview Template Code is

<asp:TemplateField HeaderText="Amt Recieve Now" ControlStyle-Width="100">
   <ItemTemplate>
    <asp:TextBox ID="txtAmountReceiveNow" runat="server" CssClass="textboxRight"
        AutoPostBack="true" OnFocus= "GVtxtAmount()"
        OnTextChanged="txtAmountReceiveNow_TextChange" 
                Text='<%#Eval("AMOUNT_RECEIVE_NOW")%>'>
     </asp:TextBox>
   </ItemTemplate>
</asp:TemplateField>

and Javascript code is as follows :

 function GVtxtAmount() {
    var txtAmountReceive = document.getElementById(
                  '<%= ((GVMaintainReceiptMaster)Container)
                         .FindControl("txtAmountReceiveNow").ClientID %>');
    var selection = txtAmountReceive.value.indexOf(".");
    alert(selection);
 };

GVMaintainReceiptMaster is ID of GridView

Help me to overe this problem.

Share Improve this question edited Feb 18, 2014 at 12:13 TheVillageIdiot 40.5k22 gold badges135 silver badges191 bronze badges asked Feb 18, 2014 at 11:43 ManivelManivel 391 gold badge2 silver badges11 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

Try this

function GVtxtAmount() {
        var txtAmountReceive = $("input[id*=txtAmountReceiveNow]")
        var selection = txtAmountReceive.value.indexOf(".");
        alert(selection);
};

You can't get text box in this way. Here is the work-around I hope it will help.

function GVtxtAmount() {
        var GVMaintainReceiptMaster = document.getElementById('<%= GVMaintainReceiptMaster.ClientID %>');

        for (var rowId = 1; rowId < GVMaintainReceiptMaster.rows.length; rowId++) {
            var txtbx = GVMaintainReceiptMaster.rows[rowId].cells[0].children[0];
            alert(txtbx.value);
        }
        return false;
    }
发布评论

评论列表(0)

  1. 暂无评论