Hi All,
I have a datagrid nested inside a datalist. On selection of a manager name from a dropdownlist, my datalist will display the all the team members reporting to him with the datagrid displaying all the customers the team members are working with. I am binding the data to the datagrid based on the unique value from datalist like below.
|
But I want bi-directional sorting to work in the datagrids. And so I tried using session variables. See the code below.
protected DataView GetClrEnrAttendance(string RepInit)
{
//log.Debug(string.Format("RepInit: {0}",RepInit));
//log.Debug(string.Format("MgrInit: {0}",MgrInit));
MgrInit = (string)Session["MgrInit"];
Getdt();
DataSet ds1 = new DataSet();
ds1 = (DataSet)Cache["ClrEnrbyMgr" + MgrInit+BeginDate+EndDate];
if (ds1 == null)
{
ds1 = DataAccessLayer.GetClrEnrbyMgr(BeginDate,EndDate,MgrInit,strVal);
Cache.Insert("ClrEnrbyMgr" + MgrInit+BeginDate+EndDate,ds1,null,DateTime.Now.AddHours(4), TimeSpan.Zero, CacheItemPriority.Default, null);
}
//ds1.WriteXml("d:\\clr.xml");
//Sort the data
DataView Dv = ds1.Tables[0].DefaultView;
Dv.RowFilter = string.Format("lead_rep_initial = '{0}'",RepInit);
SortExpression = (SortExpression == null) ? "last_first_m" : SortExpression;
SDirection = (SDirection == null) ? "ASC" : SDirection;
Dv.Sort = SortExpression + " " + SDirection;
//log.Debug(Dv.Sort);
return Dv;
}
public void BindDataList(Object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
// Retrieve the DataGrid control in the current DataListItem.
SortableGrid dGrid = (SortableGrid)e.Item.FindControl("DataGrid1");
DataRowView DrV = (DataRowView)e.Item.DataItem;
dGrid.DataSourceId = DrV.Row.ItemArray[1].ToString();
if (myHT == null)
myHT = new Hashtable();
//foreach(DataGrid dGrid in RepList)
myHT.Add(dGrid.ClientID,dGrid.DataSourceId);
}
}
public void SortByColumn(Object sender, DataGridSortCommandEventArgs e)
{
//make sure the session variables have values
if (Session["SortExpression"] == null)
{
Session["SortExpression"] = "last_first_m";
Session["SDirection"] = "ASC";
}
//change sort direction if the previous column sorted is the same as the current column sorted
SortExpression = e.SortExpression;
if ( SortExpression.Equals(Session["SortExpression"].ToString()) )
{
SDirection = (Session["SDirection"].ToString().StartsWith("ASC")) ? "DESC" : "ASC";
}
else
{
SDirection = "ASC";
}
//set the session variables to new value
Session["SortExpression"] = SortExpression;
Session["SDirection"] = SDirection;
Hashtable myHashTable = (Hashtable) Session["myHash"];
//Set DataView
SortableGrid dGrid = (SortableGrid)sender;
string RepId = myHashTable[dGrid.ClientID].ToString();
GetClrEnrAttendance(RepId);
DataView Dv = (DataView)dGrid.DataSource;
dGrid.DataBind();
}
I am having problems binding the data again to the datagrid once the datagrid column is sorted. Does anyone have idea how I can solve this? I am totally lost. I would really appreciate if anyone can help me with this. I have been beating the bush for long time and now I have to solve this problem somehow. I would really appreciate, if you could throw some light in.
Thank you so much,
Cozyitgirl