My gridview doesn't rebind in the sort event.

I am using Monorail with VS.Net 2005. Autogenerate columns is set to false. Sort expressions in the bound columns have been supplied. The gridview is being bound in page load event as well as the sorting event. I have 3 classes called staffing, location and personalphones. The DisplayGird() is being called in the  if (!IsPostBack). For some reason, the grid only takes the original sort parameters (the ones in the page_load), no matter which column header I click on.


private void DisplayGrid()
        {
                Staffing staffing = Staffing.FindByNetworkLogin(networklogin);
                if (staffing != null)
                {
                    lblSiteID.Text = staffing.Location.SiteID.ToString();
                    staffId = staffing.StaffId;
                    siteID = staffing.Location.SiteID;
                    lblSiteName.Text = staffing.Location.ShortName;
                    temp = this.strSortExpression + " " + this.strSortDirection;
                    //DataView dv = new DataView(PersonalPhones.GetPersonalDetails(siteID, staffId, manager, flag),"",temp,DataViewRowState.CurrentRows);
                    
                    DataView dv = PersonalPhones.GetPersonalDetails(siteID, staffId, manager, flag).DefaultView;
                    //temp = ViewState["strSortExpression"] + " " + ViewState["strSortDirection"];
                    dv.Sort = temp;
                    gvwPersonalDetails.DataSource = dv;
                    gvwPersonalDetails.DataBind();
                    
                }
        }
 
//The data table is in personalphones
 
  public static DataTable GetPersonalDetails(int siteID, int staffId, string manager, string flag)
        {
            string queryString;
            PersonalPhones[] personaldetails = null;
            DataTable table = new DataTable("personaldetails");
            DataColumn column;
            column = new DataColumn();
            column.ColumnName = "RE_Name";
            table.Columns.Add(column);
            column = new DataColumn();
            column.ColumnName = "homePhone";
            table.Columns.Add(column);
            column = new DataColumn();
            column.ColumnName = "blackBerry";
            table.Columns.Add(column);
            column = new DataColumn();
            column.ColumnName = "blackBerryPin";
            table.Columns.Add(column);
            column = new DataColumn();
            column.ColumnName = "Personal_CellPhone";
            table.Columns.Add(column);
            column = new DataColumn();
            column.ColumnName = "work_Phone";
            table.Columns.Add(column);
            column = new DataColumn();
            column.ColumnName = "ID";
            table.Columns.Add(column);
            if (manager == "True" && flag == "Y")
            {
                //personaldetails = (PersonalPhones[])FindBySiteId(siteID);
                queryString = @" select sid from PersonalPhones sid where sid.Location.SiteID =:siteID";
                SimpleQuery<PersonalPhones> q = new SimpleQuery<PersonalPhones>(queryString);
                q.SetParameter("siteID", siteID);
                personaldetails = q.Execute();
 
            }
            else
            {
                personaldetails = (PersonalPhones[])FindByStaffId(staffId);
            }
            
            foreach (PersonalPhones pp in personaldetails)
            {
                DataRow row = table.NewRow();
                row["RE_Name"] = pp.staffing.FirstName + " " + pp.staffing.LastName;
                row["homePhone"] = pp.HomePhone;
                row["blackBerry"] = pp.BlackBerry;
                row["blackBerryPin"] = pp.BlackBerryPin;
                row["Personal_CellPhone"] = pp.PersCellPhone;
                row["work_Phone"] = pp.WorkPhone;
                row["ID"] = pp.Id;
                if (pp.Staffing.Active)
                {
                    table.Rows.Add(row);
                }
            }
 
            return table;
 
        }

Open in new window

rajitha_mohanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sachintana DissanayakeSenior Web DeveloperCommented:
So, remove the  if (!IsPostBack) condition from the Page_Load and always call DisplayGrid() inside Page_Load.
Because you need to bind data each time you retrieve sorted data.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rajitha_mohanAuthor Commented:
I can't believe it was simple as that IsPostBack. I have been struggling for so many days. Thanks a lot! It works now
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.