How to sort a Data Grid?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fez Hussain

    How to sort a Data Grid?

    Hey, so i have a data grid that needs to be sorted when i am adding a new row

    right now it is being sorted by this way when i add a row to the grid

    2
    1
    2
    3
    4
    5

    I need it to be sorted like

    1
    2
    2
    3
    4
    5

    when they add in the same Rig ID, they Id must be below the exisiting ID on the grid so they can add the info here is my coding that i have

    Code:
    private void AddOneRigActivity(int tempRigID, string tempRigNumber, int tempprovid, int tempDepthCatID, decimal tempOpDays, decimal tempNonOpDays, decimal tempAppDays, decimal tempETours, bool tempETSFlag)
    		{
    			int tempActivityID = GetNextActivityID();
    					
    			DataRow dr = dtActivityData.NewRow(); 
    
    			int divisionID = CommonTool.ConvertStringToInt(DivisionDropdown.SelectedValue);
    			int selectedMonth = CommonTool.ConvertStringToInt(MonthDropdown.SelectedValue);
    
    			dr["ActivityID"] = tempActivityID;
    			dr["DivisionID"] = divisionID;
    			dr["RigID"] = tempRigID;
    			dr["MonthID"] = selectedMonth;
    			dr["RigNumber"] = tempRigNumber;
    			dr["ProvinceID"] = tempprovid;
    			dr["DepthCategoryID"] = tempDepthCatID;
    			dr["OperatingDays"] = tempOpDays;
    			dr["NonOperatingDays"] = tempNonOpDays;
    			dr["ApplicableDays"] = tempAppDays;
    			dr["ElectronicTours"] = tempETours;
    			dr["ETSFlag"] = tempETSFlag;
    
    			dtActivityData.Rows.Add(dr);
    			dgData.DataSource = dtActivityData;
    			dgData_DataBind();
    
    			
    			
    		}
    
    		private void dgData_DataBind()
    		{
    			dtActivityData.DefaultView.RowFilter = "";
    			dtActivityData.DefaultView.Sort = "RigNumberLen, RigNumber";
    			dgData.DataSource = dtActivityData;
    			dgData.DataBind();
    		}
  • Aimee Bailey
    Recognized Expert New Member
    • Apr 2010
    • 197

    #2
    Please specify the version of .Net you are using, there are various answers that are dependant on weather you are using .Net 2.0 or 3.5.

    Aimee.

    Comment

    • Mark Charamut
      New Member
      • Nov 2010
      • 3

      #3
      Capture the OnRowUpdated event of your data adapter and force the sort

      Comment

      Working...