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

  • Home
  • SEARCH
  • 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 6960403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:23:53+00:00 2026-05-27T15:23:53+00:00

I have a dynamic number of data elements that need to be added to

  • 0

I have a dynamic number of data elements that need to be added to my asp.net page. I am currently trying to do this by looping through a result data set like this:

protected void Page_Load(object sender, EventArgs e)
{
    UserDB db = new UserDB();
    string employeeIDOrName = Request.QueryString["employeeID"];
    DataSet ds = db.GetUserSearch(employeeIDOrName);
    DataTable table = ds.Tables[0];

    foreach (DataRow row in table.Rows)
    {
        string employeeID = row[0].ToString();
        string emailAddress = row[1].ToString();
        string phone = row[2].ToString();
        string details = emailAddress + " | " + phone;

        UserControl uc = new Controls_EmployeeSearchResults(employeeID, details);
        placeholder1.Controls.Add(uc);
    }
}

Then in the employeeSearchResults code, I have:

<div class="returnDataBoxSup" onclick="insertAddedSup('1091912','Shawna Burns');">
    <div id="searchResults" runat="server">

    </div>
</div>

for the ascx page and

public Controls_EmployeeSearchResults(string name, string details)
{
    /*<div class="returnDataBoxSup" style="overflow:hidden;" onclick="insertAddedSup('1091912','Shawna Burns');">

    <span ID="spanName" runat="server" style="text-transform:capitalize; white-space:nowrap"></span><br />
    <span ID="spanDetails" runat="server" style="font-size:0.7em; white-space:nowrap"></span>
</div>*/
    //Div
    HtmlGenericControl div1 = new HtmlGenericControl("div");
    div1.ID = "returnDataBoxSup";
    div1.Attributes["style"] = "overflow:hidden;";
    div1.Attributes["onClick"] = "insertAddedSup('1091912','Shawna Burns');";
    div1.Attributes["class"] = "returnDataBoxSup";

    //Span Name
    HtmlGenericControl span1 = new HtmlGenericControl("span");
    span1.ID = "span_" + name;
    span1.Attributes["style"] = "text-transform:capitalize; white-space:nowrap";
    span1.InnerHtml = name;

    //Span Details
    HtmlGenericControl span2 = new HtmlGenericControl("span");
    span2.ID = "spanD_" + name;
    span2.Attributes["style"] = "font-size:0.7em; white-space:nowrap";
    span2.InnerHtml = details;

    div1.InnerHtml = span1.ToString();
    div1.InnerHtml += span2.ToString(); ;
    //div1.Controls.Add(span1);
    //div1.Controls.Add(span2);
    //searchResults = new HtmlGenericControl("div");
    searchResults.InnerHtml = div1.ToString();
}

in the code behind. I first tried to add the span controls to the div, but I was receiving an exception. When I tried to add the controls to the inner html, it said that it could not convert the control type to string. Is there any way that I can do what I am trying to do?

I receive employee data in a data set, then I want to loop through those and create a stylized div for each employee record and display it on my page. Any thoughts?

  • 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-27T15:23:53+00:00Added an answer on May 27, 2026 at 3:23 pm

    Using the user control isn’t a bad idea, using a ListView could be a lot better/easier though.

    But lets say you stick with a div and a user control for now. Firstly, you don’t create usercontrols the same way you create other controls because you are part way through the page life cycle and they need to be caught up. Instead use LoadControl (see: https://stackoverflow.com/a/4786121/328968).

    Second, don’t pass the values into the constructor. Create a function in your usercontrol called LoadData and pass the values to that. After creating your usercontrol using LoadControl you call LoadData and pass in the values. LoadData takes care of loading the data into the various controls which, unlike your example, should probably already exist in your usercontrol.

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

Sidebar

Related Questions

I have an ASP.NET Dynamic Data web application, with an entity called ActivationResource .
I am trying to display a 'Software Release' table in an asp.net dynamic data
I have a page that loads a dynamic number (however many in the database
I have a number of data access methods that accept a dynamic object parameter
I have a form with a stage that has a dynamic number of groups
I have a Dynamic Data Entities Web Application that uses a database with GUIDs
I have a number of data structures (trees, queues, lists), created using dynamic allocation
I have an ASP.NET application with a lot of dynamic content. The content is
I have a a gridview with a dynamic number of columns and rows. In
I have dynamic web page with JS. There is a <textarea> and a Send

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.