Archive for tag: Repeater

Data binding not binding after submit or page refresh C#.NET or VB.NET

Today,

I have started building application and stuck in problem.

I have bind data with Repeater using DataTable it was binding on first Page_Load but when I hit submit button, it was calling another method which called repeater and getting user selection from it. But Repeater that I was getting was empty.

Then I have figured it out that EnableViewState was false, so I have added that in @Page directives EnableViewState="true". or can change from the web.config in to system.web in pages section as below:

<system.web>
   <pages enableViewState="true"  />
</system.web>

Again, I have tried running code but it didn't work for me. Then I did some trial and error for it the I have fingured it out that I didn't write on Page_Load event that it shouldn't be PostBack. So I have written following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace ExampleOfRepeaterBinding
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //Repeater binding code
            }
        }
    }
}

 

If you think that helped you please don't forget to rate and share via Facebook, Twitter, etc.

Enjoy you day and have nice weekends.