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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:06:25+00:00 2026-05-28T06:06:25+00:00

I am trying to place an asp gridview inside an asp datalist. For each

  • 0

I am trying to place an asp gridview inside an asp datalist. For each item in the datalist I would like certain values from another database table to be returned.

I have written the following code, but the gridview returns not data (I can confirm there is records in the database and the stored procedure is correct). The asp datalist is working fine.

What am I doing wrong that is not populating the gridview?

<asp:DataList runat="server" id="listResponses" DataKeyField="QuestionID" CssClass="confirm" OnItemDataBound="listResponses_ItemDataBound">
    <ItemTemplate>
    <h3 class="confirm new">Question <asp:Label ID="lblaOrder" runat="server" Text='<%# Container.ItemIndex  + 1 %>'></asp:Label></h3>
    <div class="confirm_question">
        <asp:Label ID="lblOrder" runat="server" Text='<%# Container.ItemIndex  + 1 %>'></asp:Label>
        <p class="confirm"><%# DataBinder.Eval(Container.DataItem, "QuestionText") %></p>
    </div> <!-- end confirm_question -->
    <asp:GridView runat="server" ID="gridResponses" DataKeyNames="QuestionID"">
        <Columns>
            <asp:BoundField DataField="AnswerTitle" HeaderText="ID" HeaderStyle-Width="80px" ItemStyle-CssClass="bo"></asp:BoundField>
            <asp:BoundField DataField="Responses" HeaderText="Response Count" HeaderStyle-Width="150px" />
         </Columns>
      </asp:GridView>   
  </ItemTemplate> 
</asp:DataList>

And here is the code behind.

public partial class questionnaire_responses : System.Web.UI.Page
{
    OsqarSQL GetData;
    DataTable DT;
    private string _productConnectionString;
    private SqlConnection _productConn;      

    protected void Page_Load(object sender, EventArgs e) 
    { 
        string questionnaireId = Session["qID"].ToString();
        int qid = Convert.ToInt32(questionnaireId);
        GetData = new OsqarSQL();
        string name = GetData.GetQuestionnaireName(qid);
        lblQuestionnaireName.Text = name;
        if (!IsPostBack) 
        { 
            DT = GetData.GetQuestionNameDataList(qid);
            listResponses.DataSource = DT;
            listResponses.DataBind();
        } 
    }

    private void BindGrid(GridView GridView, int questionId) 
    {
        DataTable dt = new DataTable(); 
        GetData.GetAnswerTitle(questionId);
        GridView.DataSource = dt; 
        GridView.DataBind();
    }

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

}

//Method from the data access class
public DataTable GetAnswerTitle(int QuestionId)
{
    string returnValue = string.Empty;
    SqlCommand myCommand = new SqlCommand("GetAnswer", _productConn);
    myCommand.CommandType = CommandType.StoredProcedure;
    ,yCommand.Parameters.Add(new SqlParameter("@QUESTION_ID", SqlDbType.Int));
    myCommand.Parameters[0].Value = QuestionId;
    return createDataTable(getData(myCommand));
}
  • 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-05-28T06:06:26+00:00Added an answer on May 28, 2026 at 6:06 am

    You’ve created an empty DataTable as DataSource for your GridView.

    Replace

    DataTable dt = new DataTable(); 
    GetData.GetAnswerTitle(questionId);
    GridView.DataSource = dt; 
    

    with this

    DataTable dt = GetData.GetAnswerTitle(questionId);
    GridView.DataSource = dt; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to place a class into a package where another public class is
I am trying to place a value (from an object) in a variable and
Hi im trying to place a link file in the head from a partial
I'm trying to get a Dictionary data-structure in place for one of my ASP.NET
I am trying to call the __doPostback javascript function in a asp.net page from
I'm trying to make a page where information from the database are displayed on
I'm trying to place this menu on the left hand side of the page:
I'm trying to place 4 of my image containers into a new pane, having
I am trying to place a big number in a C++ variable. The number
I'm trying to place a control that I have created on my Canvas .

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.