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

The Archive Base Latest Questions

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

After postback (click on a button) in my ASP.NET form, all the DataItem of

  • 0

After postback (click on a button) in my ASP.NET form, all the DataItem of my form are null. Why? What should I do to retrieve the content of the DataList even after postback?

protected void buttonAddRecord_Click(object sender, EventArgs e)
    {
        foreach (DataListItem item in listFields.Items)
        {
            // item.DataItem == null  WTF?
        }
    }

protected void Page_Load(object sender, EventArgs e)
    {
        BindFields();
    }

private void BindFields()
    {
        object setting = MySettings.GetSetting();

        if (!Null.IsNull(setting))
        {
            listFields.DataSource =     
                DataProvider.GetData(int.Parse(setting.ToString()));
            listFields.DataBind();
        }

        listFields.Visible = listFields.Items.Count > 0;
        emptyMessage.Visible = listFields.Items.Count == 0;
    }
  • 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-16T11:28:26+00:00Added an answer on May 16, 2026 at 11:28 am

    Found my answer here.

    What John said, the data source items
    are only avaliable when databound.
    They are no longer accessable after
    initial loading.

    You might consider having an object or
    object collection representing
    onscreen data that you update with the
    grid, then persist changes from that
    to databases.

    More precisely, I used an HiddenField to store an ID across posts and I request data from the database instead of trying to get it form the DataItem (which can’t be used outside the databinding event).

    The HiddenField control is used to
    store a value that needs to be
    persisted across posts to the server.

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

Sidebar

Related Questions

I want to call some web-service webmethods on asp.net submit button's click in order
Ok, this is painful for me because yes, I've been coding ASP.NET after classic
I have an ASP.NET button. When the button is clicked, I'd like a modal
Is there any reason an asp CompareValidator validates after postback. ie everything runs when
I am currently creating a registration form in asp.net and c#. What I want
I have a asp.net page content as below. There is an HtmlInputText control inside
I'm using asp.net and chrome and the page becomes unresponsive after a while. When
I'm working on an ASP.NET project in which the vast majority of the forms
I am working on a legacy web application written in VB.NET for ASP.NET 1.1.
I'm building a photo gallery in ASP.NET. The user can browse thumbnails along the

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.