views:

57

answers:

0

I have a ASP.NET grid view containing checkboxes and a great deal of problems surrounding it.

OnLoad gets called twice. If I check for postbacks.

    protected override void OnLoad( EventArgs e )
    {
        base.OnLoad( e );
        if ( !IsPostBack )
        {
            BindDataToGrid();
        }
    } 

and say an event triggers that also called BindDataToGrid(); Say btnFilter, removes all entries that were checked in the GridView.

    btnFilter_Click(object sender, ImageClickEventArgs e)
    {
          BindToDataGrid();
    }

BindToDataGrid gets called only twice. Once for the first OnLoad call and once for the event. The second time the debugger passes to OnLoad it doesn't go through BindToDataGrid() anymore.

    internal void BindToDataGrid()
    {
        GridView grid = GetDataBoundControl();
        grid.DataSource = null;
        if ( dsSearchResult != null )
        {
            grid.DataSource = dsSearchResult;

            grid.DataBind();

            Session[this.GetType().FullName + Context.User.Identity.Name] = dsSearchResult;
        }
    }

During this scenario, no changes become visible to the page until I manually refresh it.

Now If I don't check for postbacks, BindToDataGrid gets called three times. Twice for OnLoad and once for the event. The problem with this is that during this scenario, the checked items in the checkboxes only register during the first call to OnLoad, during the second call to OnLoad the grid's data refreshes because of the second bind.

I need it so that any events that result in binding data to the grid reflect their changes. That's the expected behavior isn't it? The way I see it, the best solution would be to get rid of that 2nd call to OnLoad. I don't even get why it's there. Any other suggestion would be nice. I've been messing around with this code for days.