This is a migrated thread and some comments may be shown as answers.

Modify Value

1 Answer 22 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christopher Blickley
Top achievements
Rank 2
Christopher Blickley asked on 09 Mar 2010, 10:23 PM
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

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;  
              
        }  
 
    }  

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 10 Mar 2010, 08:32 AM
Hi,

The grid sorts the data using the underlying datasource .The changes you make to the ItemCreated event is applied only after the Sort command is fired ,so this wont do any help. A suggestion would be to  apply custom sort and make changes to the datasource  in the sort command as shown in the below link.
http://www.telerik.com/help/aspnet-ajax/grdapplycustomsortcriteria.html

Thanks,
Princy
Tags
Grid
Asked by
Christopher Blickley
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 1
Share this question
or