How do I find the Client ID of control within an ASP.NET GridView?

后端 未结 6 1627
旧时难觅i
旧时难觅i 2020-12-03 14:22

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:



        
6条回答
  •  一向
    一向 (楼主)
    2020-12-03 14:33

    I just do this...

    var tbl = document.getElementById('<%=GridView.ClientID%>');
    var checkBox = tbl.rows[i].cells[11].getElementsByTagName("input")[0].id;
    

    the cell should always be the same and it gets rendered into an input. You may have to change the number at the end if you have more then one input in that cell. This will give you the new clientid/id of the input object (checkbox or whatever)

提交回复
热议问题