Not able to access dynamically created textboxes in a gridview using Javascript


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Not able to access dynamically created textboxes in a gridview using Javascript

  1. #1
    Join Date
    Dec 2006
    Posts
    1

    Not able to access dynamically created textboxes in a gridview using Javascript

    Hi,

    For e.g i need to display a list of employees. So in my gridview i have my first column as EmpName and 2nd and 3rd column and 4th column as template field with textboxes.

    So for n number of employees , n number of textboxes would be created dynamically.

    I need to access these textboxes in the javascript, as i need to add the values in 2nd and 3rd column and polpulate them in 4th column of each rowin a grid onblur of the 2nd column .

    Can anyone let me know how can i get access to these controls (to add the values) in Javascript?

    ASPx page

    <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
    <Columns>
    <asp:BoundField DataField="EmpName" HeaderText="EmpName" />
    <asp:TemplateField HeaderText="Value1">
    <ItemTemplate>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Value2">
    <ItemTemplate>
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Value3">
    <ItemTemplate>
    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateField>


    </Columns>
    </asp:GridView>


    Thanks,
    Mathew

  2. #2
    Join Date
    Jun 2011
    Posts
    2

    Smile

    HI matthew

    you can get reference of text box by prefixing the grid id you give

    once the page gets loaded into browser grid becomes a table and it will have the same id as grid and whatever the objects that you placed inside the grid will have the id of the grid and its own id but seperated with '_'.

    Now using the getElementsById or GetElementsByName against the document object of javascript you can get the reference of text box

    hope this helps you

Similar Threads

  1. Replies: 2
    Last Post: 09-08-2003, 02:33 AM
  2. Replies: 1
    Last Post: 01-30-2003, 08:03 AM
  3. Replies: 0
    Last Post: 05-16-2001, 05:24 PM
  4. JavaScript and MS access databases
    By amukelani shandlale in forum Web
    Replies: 1
    Last Post: 04-24-2001, 11:46 AM
  5. Sample Sites.
    By Murray Foxcroft in forum Web
    Replies: 5
    Last Post: 11-02-2000, 02:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center