Last post Sep 12, 2008 08:55 PM by jtlembke
Sep 08, 2008 09:08 PM|jtlembke|LINK
Here's a simple one...
I have a value in my Entity model that tells me if page elements should be read only. I want to check that value before the page displays and make my Gridview/Formview etc readonly. How do get to that value?
I want to do something like:
Sep 09, 2008 03:51 AM|sjnaughton|LINK
I guess this would need to be a custom page, i would use an IAutoFieldGenrator and set each item to to be a readonly Field
see my Generate Columns/Rows (using IAutoFieldGenerator) in my
A DynamicData Attribute Based Permission Solution using User Roles. series.
In the above
Generate Columns/Rows (using IAutoFieldGenerator) I create a
DynamicReadonlyField in the FilteredFieldsManager if a field is readonly, what you could do is check if
IsClosed and then set all fields ro readonly.
Hope this helps [:D]
Sep 09, 2008 10:21 AM|jtlembke|LINK
Sadly Steve, I'm seeing how remedial my question is. I apologize:
I can't figure out how to even see my database values in code. I have the custom page, and I can make the necessary elements readonly. But I want the page to render as readonly based on what I see in my data, particularly the "IsClosed" field. I'm using
Entity Framework, and on my page, for the life of me I can't get to those values.
This is like forgetting "if" syntax, or something
Sep 09, 2008 11:38 AM|Adult|LINK
Use OnDataBound event,where u can get a data from current Row
Sep 09, 2008 03:28 PM|jtlembke|LINK
Ok, well at least I'm on the right track, but that's not quite doing it. I'm using a FormView as a details section for my Grid. When the user is on an item in the master grid whose "IsClosed" column reads true, I want the details section to go ReadOnly.
I had thought that on FormView1_ItemCreated I could simply check the current IsClosed value and then make the FormView readonly.
In the object viewer tool in debug, I can drill down into the FormView to the DataItem, and I can see what I need in the WrappedEntity, but I don't know how to get at it programmatically.
This link from Diego Vega seemed promising but I keep getting "Unable to cast object of type 'MyEntityType' to type 'System.Data.Linq.EntitySet`1[MyEntityType]'."
Please, I've been stuck on what I thought was a simple thing for way too long. Any help would be much appreciated.
Sep 09, 2008 07:34 PM|jtlembke|LINK
Ok, if I could click Diego Vega as having the right answer I would. I used a variation of his solution that worked.
If you want to read values and act on them before the page displays, it appears the only way to get at them is via DataItem. If you are working with a DataView, you can get to that with e.row.DataItem. However if you are using a FormView, you must first
cast sender as a FormView type to get the DataItem. The rest is all about ICustomTypeDescriptor, which knowledge was delivered by Diego. Something like this should work:
//Don't forget these!
protected void FormView1_ItemCreated(object sender, EventArgs e)
FormView fv = (FormView)sender;
//Not my favorite way of stopping this, but the event gets called
//multiple times and gives an exception since DataItem is null sometimes
if (fv.DataItem != null)
ICustomTypeDescriptor descriptor = fv.DataItem as ICustomTypeDescriptor;
var prop = descriptor.GetProperties().Cast().First();
//Get the current instance of your entity data
MyEFEntity entity = (MyEFEntity)descriptor.GetPropertyOwner(prop);
//Now do something based on your data, like make a form ReadOnly...
if (entity.MyProperty == "myvalue")
Sep 09, 2008 09:05 PM|ricka6|LINK
Thanks for posting the solution. I'll let Diego Vega know his blog was useful.
Sep 12, 2008 08:55 PM|jtlembke|LINK
And I actually did get Diego's code to work as posted in his blog. I don't know what the problem was before.. :(