ASP.NET: OnLoad event issue in DataGrid

523 views Asked by At

As I will lose the modified data when move to next page in DataGrid in Edit model, then I found if I bind the data in Onload event, I won't lose the modified data.

Another word, I cannot to add some event to bind data for some reasons.

So I bind the data source in Onload event as follow:

protected override void OnLoad(EventArgs e)
    {  
     if (Page.IsPostBack){
       if (_grid != null && _grid.DataSet.CurrentTable != null && _grid.EditMode == EditModeValues.Edit)
            {
                DataGrid.DataBindList();
                DataGrid.DataSet.CurrentTable.AcceptChanges();

             }
        }
    }

and the DataBindList core code:

    public int DataBindList()
    {
        var count = 0;
        if (_dataSet.CurrentTable != null)
        {
            DataSource = _dv;
            DataBind();
            count = _dv.Count;
        }
        else
        {
            _dv = null;
            DataSource = null;
            DataBind();
        }
        return count;
    }

but after I DataBind the data, I found the event OnBubbleEvent(object source, EventArgs args) cannot be trigerred, if I didn't bind the data, the OnBubbleEvent can be triggered,

I need to use OnBubbleEvent to add a new item in DataGrid, and my OnBubbleEvent code:

        protected override bool OnBubbleEvent(object source, EventArgs args)
    {
        DataGridCommandEventArgs dgCmd = args as DataGridCommandEventArgs;

        if (dgCmd != null)
        {
            switch (dgCmd.CommandName)
            {
                case "Add":
                    AddLineItem(dgCmd.Item);
                    return true;
            }
        }

        return base.OnBubbleEvent(source, args);
    }

I don't know why, can anyone help me on this?

0

There are 0 answers