Hello,
I've been trying to come up with a way to modify a value in the grid based on business logic within the application. For example, if showing a list of employee's, the business logic checks to see if they have access to salary information for the employee's department. Based on the complexity of the logic, it is done within the applicaiton and not in SQL.
So, if the user does NOT have access to the salary, I would like to change the cell to say "Protected" or something similar. I can do this fine, however, the user could still sort the grid and infer the salary range based on where the records show up in the sort results. What I can't figure out how to do is change the underlying value to 0 (zero) when checking this logic. I have tried doing this in the ItemCreated event and the ItemDataBound event, but whatever I do, it seems to continue knowing how to sort based on the real value and doesn't honor the new 0 (zero) I put in there. Here is what I have tried....a little overkill now, but I was trying to modify they value everywhere I could.
Does anyone know how to do this?
Thanks,
Chris
I've been trying to come up with a way to modify a value in the grid based on business logic within the application. For example, if showing a list of employee's, the business logic checks to see if they have access to salary information for the employee's department. Based on the complexity of the logic, it is done within the applicaiton and not in SQL.
So, if the user does NOT have access to the salary, I would like to change the cell to say "Protected" or something similar. I can do this fine, however, the user could still sort the grid and infer the salary range based on where the records show up in the sort results. What I can't figure out how to do is change the underlying value to 0 (zero) when checking this logic. I have tried doing this in the ItemCreated event and the ItemDataBound event, but whatever I do, it seems to continue knowing how to sort based on the real value and doesn't honor the new 0 (zero) I put in there. Here is what I have tried....a little overkill now, but I was trying to modify they value everywhere I could.
Does anyone know how to do this?
Thanks,
Chris
void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) |
{ |
if (e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem || e.Item.ItemType == Telerik.Web.UI.GridItemType.Item) |
{ |
Telerik.Web.UI.GridDataItem item = (Telerik.Web.UI.GridDataItem)e.Item; |
System.Data.DataRowView dataRow = (DataRowView)item.DataItem; |
if (dataRow != null && !SecurityManager.HasAccessToGroupByRole(BusinessServices.Security.RoleCode.ViewSalary, dataRow["Dept"].ToString() )) |
{ |
item["Annual_Salary"].Text = "Protected"; |
dataRow["Annual_Salary"] = 0; |
((System.Data.DataRow)dataRow.Row)["Annual_Salary"] = 0; |
gridData.Tables[0].Rows[item.DataSetIndex]["Annual_Salary"] = 0; |
} |
} |
} |
void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
{ |
if (e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem || e.Item.ItemType == Telerik.Web.UI.GridItemType.Item) |
{ |
Telerik.Web.UI.GridDataItem item = (Telerik.Web.UI.GridDataItem)e.Item; |
System.Data.DataRowView dataRow = (DataRowView)item.DataItem; |
if (!SecurityManager.HasAccessToGroupByRole(BusinessServices.Security.RoleCode.ViewSalary, dataRow["Dept"].ToString() )) |
{ |
//item["Annual_Salary"].Text = "Protected"; |
dataRow["Annual_Salary"] = 0; |
((System.Data.DataRow)dataRow.Row)["Annual_Salary"] = 0; |
gridData.Tables[0].Rows[item.DataSetIndex]["Annual_Salary"] = 0; |
} |
} |
} |