Articles in this Series
- Introduction - A DynamicData Attribute Based Permission Solution using User Roles.
- Part 1 - Permissions Attribute (Metadata) Classes.
- Part 2 - Sample Metadata for project.
- Part 3 - The Helper Extension Methods.
- Part 4 - Limit Tables shown on Default page and List, Edit & Details etc.
- Part 5 - Generate Columns/Rows (using IAutoFieldGenerator)
- Part 6 - Miscellaneous bits
- Part 7 - Updating the ListDetails Page
- DynamicData - Limit the Filter Fields
- DynamicData - Automatic Column Update
- DynamicData - Limit Data Displayed By User
Limiting Data by the Current User
This is a really simple scenario where the table has a column which is update with the current user name at record creation (see: Automatic Column Update how to automatically update tables) all that is required is to add a WhereParameter to the pages LinqDataSources. In the Page_Load add the line for each LinqDataSource on the page (this line of code is for the List.aspx page).
GridDataSource.WhereParameters.Add(new Parameter("CreatedBy", DbType.String, User.Identity.Name));Obviously you may whish to add a CheckBox or RadioButton to toggle this feature or even add a filter to filter several users at once (see Marcin Dobosz Blog post Dynamic Data samples: Extending the FilterRepeater for details on how to extend the FilterRepeater)
14 comments:
Hi,
I appreciate your postings. I need to filter data by 2 user_code (current user and global user). Using WhereParamers.Add the column name needs to be unique. Using the GridDataSource.Where also mbreaks the DynamicFilters. Do you know a way around this?
regs,
Nic
Hi have a look at this project on Codeplex http://www.codeplex.com/DynamicDataFiltering I think this will do what you want. And i will be doing a series on this soon :D
Steve,
I know that when you set "ScaffoldColumn(false)", you can hide the column in the display but can this be done conditionally ? For example, I have a field called "DeletedFlag" and when the action is Insert, I want this field hidden but when the action is Edit, I want the field displayed.
Thanks
fxl
Hi have a look at this article here: http://csharpbits.notaclue.net/2008/10/dynamic-data-hiding-columns-in-selected.html
Steve :D
What if instead of equality I want to check Greater than or less than values... it will not work..
Hi there Manish, I would recommend DD4 with VS2010 as that support QueryExtenders which allow much greater flexibility.
Steve
GridDataSource.WhereParameters.Add("UserId", DbType.Int32, "3");
throw that error
No property or field 'UserId1' exists in type 'Web'
I think the filterrepater using that parameter.
Hi Anonymous there must be a property on the entity and with that type, otherwise you will get that error.
Steve :)
Hi Steve. Thanks for your quick reply.
I m just wondering is that possible? context based filter.
// Filter The Context
DBCntxt.Webs.UserId = "3";
DBCntxt.Comments.UserId "3";
DBCntxt.Products.UserId "3";
// Register The Context
model.RegisterContext(typeof(DBCntxt), new ContextConfiguration() { ScaffoldAllTables = true
});
I know, i can't use like this but is there any way to do this?
Hi, again :) I'm not that deep into L2S or EF to know sorry, haqve you any links to where you got that and I'll investigate it and do an article on it. (I'll credit you of course)
Steve :D
Hi :). This is my idea. There is no article, link or anything about this question. I have searched the internet and can't find anything about this question. I think there is no solution for this :).
by the way my name is Oguz. Very nice to meet you.
Hi Oguz, I'll have a look into it.
Steve :)
I will be eagerly waiting :)
Thanks.
Post a Comment