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 7708513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:37:52+00:00 2026-06-01T00:37:52+00:00

I have an ASP Datalist with a nested GridView. I am trying to display

  • 0

I have an ASP Datalist with a nested GridView.
I am trying to display an ASP label for each list item where the gridview has more than 6 rows and keep it hidden for those list items where the gridview has < 6 rows.

Here is the datalist:

<asp:DataList runat="server" id="listResponses" DataKeyField="QuestionID" OnItemDataBound="listResponses_ItemDataBound" Width="100%">
                <ItemTemplate>
                    <div class="question_header">
                        <p><strong><asp:Label ID="lblOrder" runat="server" Text='<%# Container.ItemIndex  + 1 %>'></asp:Label>. <%# DataBinder.Eval(Container.DataItem, "QuestionText") %></strong></p>
                    </div> <!-- end question_header -->
                    <asp:GridView runat="server" ID="gridResponses" DataKeyNames="AnswerID" AutoGenerateColumns="False" CssClass="responses" AlternatingRowStyle-BackColor="#f3f4f8">
                        <Columns>
                            <asp:BoundField DataField="AnswerTitle" HeaderText="Answer Title" HeaderStyle-ForeColor="#717171" ItemStyle-Width="250px"></asp:BoundField>
                            <asp:BoundField DataField="Responses" HeaderText="Response Count" HeaderStyle-ForeColor="#717171" HeaderStyle-Width="100px" />
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <div class="pbcontainer">
                                        <div class="progressbar"></div>
                                        <asp:HiddenField ID="hiddenValue" runat="server" Value='<%# Eval("Responses") %>' />
                                     </div>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                    <a><asp:Label runat="server" ID="lblShowResponses" Visible="false"></asp:Label></a>  
                </ItemTemplate>
            </asp:DataList>

The label I am trying to update is lblShowResponses.

The method to populate the datalist:

// populate datalist.
DT = GetData.GetQuestionNameDataList(qid);
listResponses.DataSource = DT;
listResponses.DataBind(); 

And the gridview is populated as follows:

    protected void listResponses_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        GridView gridResponses = (GridView)e.Item.FindControl("gridResponses");
        BindGrid(gridResponses, (int)listResponses.DataKeys[e.Item.ItemIndex], DT.Rows[e.Item.ItemIndex][2].ToString());
    }

    // Get the question ID from the datalist and parse the parameters to BindGrid
    protected void listResponses_ItemDataBound(object sender, DataListItemEventArgs e)
    {
         GridView gridResponses = (GridView)e.Item.FindControl("gridResponses");
         BindGrid(gridResponses, (int)listResponses.DataKeys[e.Item.ItemIndex], DT.Rows[e.Item.ItemIndex][2].ToString());
    }

    private void BindGrid(GridView GridView, int questionId, string questionType)
    {
        // get the answerID and title for the current question.
        DataTable answersDataTable = new DataTable();
        answersDataTable = GetData.GetAnswerResponses(questionId);
        DataTable tempResponses = new DataTable();

        // checkbox question type - loop through each answer and obtain the number of responses.       
        for (int answer = 0; answer < answersDataTable.Rows.Count; answer++)
        {
            // populate tempaory datatable and replace DT with the response count.
            string answerID = answersDataTable.Rows[answer][0].ToString();
            tempResponses = GetData.getIndividualQuestionResponses(questionId, answerID);
            answersDataTable.Rows[answer][2] = tempResponses.Rows[0][0];
        }
        if (GridView.Rows.Count > 6)
        {
            for (int x = 6; x < GridView.Rows.Count; x++)
            {
                GridView.Rows[x].Visible = false;
            }

            // I want to populate the label here!!!!!!
       }

   }

How can I update/populate the label lblShowResponses when the gridview contains more than 6 rows?

  • 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-01T00:37:53+00:00Added an answer on June 1, 2026 at 12:37 am

    Not sure if this would help you, pass the DataListItemEventArgs param “e” to the BindGrid method and in the location you want to populate the label and use

    (e.Item.FindControl("lblShowResponses") as Label).Text = "Test";
    (e.Item.FindControl("lblShowResponses") as Label).Visible = true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to place an asp gridview inside an asp datalist. For each
i have a datalist control <ItemTemplate> <asp:Label ID=lblAddressID runat=server Text='<%# Bind(StudentName) %>'/> <asp:Label ID=lbl
I have a DataList and inside of each item there is an ImageButton that
I have a DataList like so: <asp:DataList ID=dlMyList runat=server RepeatColumns=5 RepeatDirection=Horizontal CellSpacing=5 > <ItemTemplate>
I have a datalist control <asp:DataList ID=DataList1 runat=server DataKeyField=AdmissionNo OnCancelCommand=DataList1_CancelCommand1 OnEditCommand=DataList1_EditCommand1 OnUpdateCommand=DataList1_UpdateCommand1 Width=300px> <ItemTemplate>
I have a table that is created in a DataList in ASP.Net. This table
I have a datalist being generated with ASP, but unfortunately the jQuery script that
I have a asp DataList that gets populated by a DataTable . <asp:PlaceHolder ID=ph3
I have written this datalist : <div class=story runat=server> <asp:DataList ID=DataList2 runat=server Height=16px Width=412px>
In my .aspx page I have my DataList: <asp:DataList ID=DataList1 runat=server DataKeyField=ProductSID DataSourceID=SqlDataSource1 onitemcreated=DataList1_ItemCreated

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.