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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:34:20+00:00 2026-05-14T23:34:20+00:00

I populate web form with dynamic list of exams from database. I want user

  • 0

I populate web form with dynamic list of exams from database. I want user to enter examination marks for each exam. There is list of exam titles and textbox near each title.

I create list with repeater control (ViewState is disabled) :

<asp:Repeater ID="rptExams" runat="server" onitemdatabound="rptExams_ItemDataBound" >    
        <ItemTemplate>        
                <tr>
                    <td>                        
                        <asp:Literal runat="server" ID="ltTitle"/>
                    </td>
                    <td>
                        <asp:HiddenField runat="server" ID="hfId"/>
                        <asp:Textbox runat="server" ID="tbMark"/>
                    </td>
                </tr>
        </ItemTemplate>    
    </asp:Repeater>

And bind data to repeater on page_init:

class Exam
{
    public int Id { get; set;}
    public string Title { get; set;}
}
...
// this list is retrieved from database actually 
Exam[] Exams = new Exam[]
{
    new Exam { Id = 1, Title = "Math"},
    new Exam { Id = 2, Title = "History"}                                        
};
...
protected void Page_Init(object sender, EventArgs e)
{
    rptExams.DataSource = Exams;
    rptExams.DataBind();
}

So far so good. Then I have to retrieve data on postback. I have two ways but both of them looks ugly.
Idea is to store dynamically created databounded controls on ItemDataBoundEvent in Page_Init stage, and process their values in Page_Load stage. It looks like this:

private Dictionary<HiddenField, TextBox> Id2Mark = new Dictionary<HiddenField, TextBox>();

protected void rptExams_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    ...
    if (IsPostBack)
    {
        var tbMark = (TextBox)e.Item.FindControl("tbMark");
        var hfId = (HiddenField)e.Item.FindControl("hfId");

        // store dynamically created controls 
        Id2Mark.Add(hfId, tbMark);
    } 
    ...    
}

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        foreach (var pair in Id2Mark)
        {
            int examId = Int32.Parse(pair.Key.Value);
            string mark = pair.Value.Text;
            // PROCESS 
        }
...

I’m completely sure there is a better way to retrieve data from dynamically created controls. Thank you in advance!

  • 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-14T23:34:21+00:00Added an answer on May 14, 2026 at 11:34 pm

    Here’s how you can do it:

    First, don’t rebind the data on postback – it’s not necessary. Only bind it on the first call of the page.

    protected void Page_Init(object sender, EventArgs e)
    {
        if (!IsPostBack){
            rptExams.DataSource = Exams;
            rptExams.DataBind();
        }
    }
    

    You won’t need the Dictionary neither.

    Then, on a postback, you can get to the bound data as follows:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            foreach (RepeaterItem item in rptExams.Items)
            {
                HiddenField hfId = item.FindControl("hfId") as HiddenField;
                TextBox tbMark = item.FindControl("tbMark") as TextBox;
    
                int examId = Int32.Parse(hfId);
                string mark = tbMark.Text;
                // PROCESS 
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a survey-type form that's being populated from a web database on the
I'm trying to populate a dropdown list in my web page from a mysql
For example, I want to populate a gridview control in an ASP.NET web page
I populate a DataGrid from a CollectionViewSource. Each row has a delete button. On
I have two objects: Form . A form that I populate from a JSP
Currently I am retrieving list items from a sharepoint list via the provided web
I'm loading a csv file into my database via a web form. The order
Say I want to populate a JPA entity using values supplied by a user
I populate the GridView.DataSource from a EntityFramework Model: gwTimeLog.DataSource = _entities.TimeLogs; When a new
Right now to populate my GridViews I'm using a extended BaseAdapter class on each

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.