Does anyone know if there is a way to set the SelectedValue of a drop down on the insert template? I would need to do this at run time.
The situation is that for certain non-priveleged users, they can only insert rows for a selected drop down field. So, for those users I would want to set the SelectedValue and make the field Readonly. For priveleged users, they would be able to select
anything for that field.
I think you can bind the selectedvalue property in the markup. As far as the privilege is concerned, you can bind the enabled property so it's disabled for this users that shouldn't update it; or handle the RowDataBound, ItemDataBound or whatever and set the
enabled property there. I really depends on how you've set up the page/controls.
Thanks for your suggestion, can I ask which markup are you talking about? I think I could make it work by changing ForeignKey_Edit.ascx.cs. It's a bit of a hack, but i'm not that pure:)
you will notice the table.GetColumnValuesFromRoute(Context)) this getts any values from the route but if you pass it to a local variable first you can manually add you own default values as it is a collection of type IDictionary<string, object> then pass
the updated dictionary into the SetMetaTable extension method.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Marked as answer by mikew on Jan 15, 2012 11:29 AM
mikew
Member
33 Points
20 Posts
Set default for drop down on insert template
Jan 14, 2012 03:25 PM|LINK
Does anyone know if there is a way to set the SelectedValue of a drop down on the insert template? I would need to do this at run time.
The situation is that for certain non-priveleged users, they can only insert rows for a selected drop down field. So, for those users I would want to set the SelectedValue and make the field Readonly. For priveleged users, they would be able to select anything for that field.
Thanks for your help!
MetalAsp.Net
All-Star
112180 Points
18257 Posts
Moderator
Re: Set default for drop down on insert template
Jan 14, 2012 03:30 PM|LINK
mikew
Member
33 Points
20 Posts
Re: Set default for drop down on insert template
Jan 14, 2012 05:41 PM|LINK
Thanks for your suggestion, can I ask which markup are you talking about? I think I could make it work by changing ForeignKey_Edit.ascx.cs. It's a bit of a hack, but i'm not that pure:)
Mike
MetalAsp.Net
All-Star
112180 Points
18257 Posts
Moderator
Re: Set default for drop down on insert template
Jan 14, 2012 05:57 PM|LINK
sjnaughton
All-Star
27320 Points
5459 Posts
MVP
Re: Set default for drop down on insert template
Jan 15, 2012 10:51 AM|LINK
I am assuming this is DD for .Net 4 if so look at the Insert page template codfe behind it creates a collection
protected void Page_Init(object sender, EventArgs e) { table = DynamicDataRouteHandler.GetRequestMetaTable(Context); FormView1.SetMetaTable(table, table.GetColumnValuesFromRoute(Context)); DetailsDataSource.EntityTypeFilter = table.EntityType.Name; }you will notice the table.GetColumnValuesFromRoute(Context)) this getts any values from the route but if you pass it to a local variable first you can manually add you own default values as it is a collection of type IDictionary<string, object> then pass the updated dictionary into the SetMetaTable extension method.
Always seeking an elegant solution.