Get reference to a control within GridView in JS

Last post 11-18-2008 11:56 PM by pyu.agrawal. 3 replies.

Sort Posts:

  • Get reference to a control within GridView in JS

    11-18-2008, 7:21 AM
    • Member
      628 point Member
    • pyu.agrawal
    • Member since 11-01-2007, 1:07 PM
    • Pune
    • Posts 194

    Hi

    I need to get reference to textboxes within a gridivew through JavaScript, How do I?

    I tried this, but all in vain

    Thanks

    Peeyush

    Do mark the most helpful reply/replies as "Answer".
  • Re: Get reference to a control within GridView in JS

    11-18-2008, 7:30 AM

     It would be better if you could see the viewsource of the particular for which you need to refer the textbox control.

      the textboxes in the Gridview appear in a sequncial order so you can find the count of the GRidview

    and see the numbers of textboxes that are vailable to you to access them
     

    Regards,
    Pavithru Pinnamaneni
  • Re: Get reference to a control within GridView in JS

    11-18-2008, 11:38 AM
    Answer
    • All-Star
      75,123 point All-Star
    • NC01
    • Member since 08-26-2005, 7:33 PM
    • Posts 13,974

    This is all that you need to do to access a TextBox that is in a GridView from JavaScript:

    <form id="form1" runat="server">
     <asp:GridView ID="GridView1" AutoGenerateColumns="False" ShowHeader="True" runat="server">
      <Columns>
       <asp:TemplateField>
        <ItemTemplate>
         <asp:TextBox ID="gridTextBox" onchange="gridTextBoxOnChange(this);" runat="server"></asp:TextBox>
        </ItemTemplate>
       </asp:TemplateField>
      </Columns>
     </asp:GridView>
    </form>

    <script type="text/javascript">
    <!--
    function gridTextBoxOnChange(elementRef)
    {
     alert('TextBox: ' + elementRef.id + ' Value: ' + elementRef.value);
    }
    // -->
    </script>

    NC...

  • Re: Get reference to a control within GridView in JS

    11-18-2008, 11:56 PM
    • Member
      628 point Member
    • pyu.agrawal
    • Member since 11-01-2007, 1:07 PM
    • Pune
    • Posts 194

    Hi NC01,

    onchange="gridTextBoxOnChange(this);"  worked like charm.

    Thanks.

    Peeyush

    Do mark the most helpful reply/replies as "Answer".
Page 1 of 1 (4 items)