Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8133295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:33:36+00:00 2026-06-06T09:33:36+00:00

I have an .ascx control inside la page. In that control, I have a

  • 0

I have an .ascx control inside la page. In that control, I have a GridView with expandable content. So far so good. My problem started when I tried to create Expand all/Collapse All buttons. For some reason, I have to put the Javascript functions in the .aspx page, otherwise they can’t be found.

How can I retreive the gridview data from the control? I want to call my expandOne function for each row, but I can’t acces the rows. expandOne works fine on one row.

var gvObject = document.getElementById('GridView1'); 

is null.

var gvObject = $('GridView1');

gives something that is not a grid (gvObject.rows is null) and gvObject.length == 0

var grid = document.getElementById('<%=GridView1.ClientID %>');

will crash (‘GridView1’ doesn’t exist in the current context).

.

Here is the HTML

<asp:GridView ID="GridView1" runat="server" AllowPaging="false" AutoGenerateColumns="False" ShowHeader="false">
<Columns>
  <asp:TemplateField>
      <ItemTemplate>
          <a href="javascript:collapseExpand('Job-<%# Eval("Index") %>');" >
          <img id="imageJob-<%# Eval("Index") %>"  alt="Click to show/hide orders"  border="0" src="../images/plus.png" /></a>
      </ItemTemplate>
  </asp:TemplateField>
  <asp:BoundField DataField="TitleCnt" />

  <asp:TemplateField>
      <ItemTemplate>
          <tr><td colspan="100%">
              <div id="Job-<%# Eval("Index") %>" style="display:none; left:25px;" class="answer">
                <asp:Label Text="Some content" runat="server"></asp:Label>
              </div>
          </td></tr>
      </ItemTemplate>
  </asp:TemplateField>
</Columns>
</asp:GridView>

and the javascript

function expandOne(obj) {
    var gvObject = document.getElementById(obj);
    var imageID = document.getElementById('image' + obj);
    gvObject.style.display = "inline";
    imageID.src = "../images/moins.png";
}

function ExpandAll() {
    var gvMaster = $('GridView1');
    for (i = 0; i < gvMaster.rows.length; i++) {
        expandOne('Job' + i);
    }
}

Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:33:37+00:00Added an answer on June 6, 2026 at 9:33 am

    If you are using .Net 4, you can set set the GridView’s ClientIDMode="Static". This will result in a table on the client where the id property is “GridView1”. Then this should get you the table:

    var gvObject = document.getElementById('GridView1');

    And your jQuery selection will work too, but you have to include the # character:

    var gvObject = $('#GridView1');

    For info on the ClientIDMode, see http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have 2 textbox controls inside a usercontrol TextBoxUC.ascx i have a page.aspx that
I have user control inside a page with single repeater. The problem is when
I have a ASCX control that sits inside of a CMS that is written
I have two instances of an Address.ascx control in an ASP.NET MVC page. <h1>Shipping
my structure is like this: master page aspx(web form) ascx(user control) I have a
I have a page containing a control called PhoneInfo.ascx. PhoneInfo is dynamically created using
I have a radio button list control on my ascx page and have a
For example, I have a user control(ascx) with a label inside, I will use
I currently have a dropdown inside an ascx control. I need to find it
I have created a control and added a TextBox inside that control, I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.