fez

fez

  • NA
  • 3
  • 3.2k

DataGrid Sort C#

Oct 27 2010 1:54 PM
 
hello, i am trying to sort a data grid when adding a new row

right now, when a client adds a new row with the same ID it goes

2
1
2
3
4
5

(notice the ID 2 is at the very top of the list)

I need it to go

1
2
2
3
4
5

(the 2 needs to be below the 2 when it's added)

here is the code i have

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.Sel ectedValue);
int selectedMonth = CommonTool.ConvertStringToInt(MonthDropdown.Select edValue);

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";
//there is a reason why its sorted by RigNumberLen then Rignumber that has to stay the same

dgData.DataSource = dtActivityData;
dgData.DataBind();
}

Answers (2)