Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get the gridview item template element in javascript
Posted

Try like this
XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"  >
            <Columns>
                <asp:TemplateField>
                <ItemTemplate>
                 <asp:TextBox ID="Textbox1" runat="server" CssClass="DropDownFont" Font-Size="XX-Small" Text='<%# Eval("Column1")%>' > </asp:TextBox>
                </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <script type="text/javascript">
            var table = document.getElementById("GridView1");

            if (table.rows.length > 0) {
                //loop the gridview table
                for (var i = 1; i < table.rows.length; i++)
                {
                    //get all the input elements
                    var inputs = table.rows[i].getElementsByTagName("input");
                    for (var j = 0; j < inputs.length; j++) {
                        //get the textbox1
                        if (inputs[j].id.indexOf("Textbox1") > -1) {
                            alert(inputs[j].value);
                        }

                    }

                }
            }

        </script>

Refer:
Populate Gridview Edit Item Template TextBox with value from TextBox using Javascript.[^]
How to Find Gridview Item template texbox using Javascript[^]

This may help.
 
Share this answer
 
v4
Comments
Member 10517120 31-Jan-14 2:14am    
TNX A LOT
Gitanjali Singh 31-Jan-14 2:19am    
Welcome :)
You wont be able to get the ItemTemplate in the Javascript
as the girdview will be rendered in the Web Browser as Table only with TR's TD's

you can get the controls inside the Item template by iterating the rows(TR) and columns(TD) in Javascript
 
Share this answer
 
Comments
Member 10517120 31-Jan-14 1:57am    
thats what i need controls inside template field for validation in javascript
Karthik_Mahalingam 31-Jan-14 1:59am    
check solution2
kdontje69 19-Dec-18 17:12pm    
Yea you are totally wrong. Solution 2 gives you exactly what you need.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900