showing / hiding template fields in detailsview
Hi, I have a detailsview control in which I would like to hide a templatefield when the control is in read only mode and display the template when the form is in edit mode.
here is the snipet from the details view control. I dont want to be able to see the header text at all in readonly mode.
<asp:TemplateFieldHeaderText="Access Type" visible = "false">
<ItemTemplate><asp:Labelid="lblAccessId"runat="server"Text='<%# Eval("_accessLevelID") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownListID="ddlaccessTypes"runat="server"DataSourceID="objAllAccessTypes"DataTextField="_accessLevelType"DataValueField="_accessLevelID"
selectedValue='<% # bind("_accessLevelId") %>'
/></EditItemTemplate>
</asp:TemplateField>
and here is the snippet from the code behind file
ProtectedSub dvProviders_PreRender(ByVal sender AsObject, ByVal e As EventArgs)
If dv_providers.CurrentMode = DetailsViewMode.Edit Then
dv_providers.Rows(16).Visible = True
EndIf
EndSub
If I set the <asp:TemplateFieldHeaderText="Access Type" visible = "false">
then the Sub dvProviders_PreRender doesnt display the row when the template is in edit mode.
I suspect that this is because visible is set to false in the template which ultimately overrides the onprerender event.
The details view control is only displayed once a selection is made from a listbox on the page.
The solution must lie in being able to set the visiblle attribute of the template to false programmatically but I'm not sure how to do this when the detailsview control doesnt exist on the page until
a selection is made from the list box.
I have looked at many posts on this topic but cant find a solution. Any help would be appreciated.
|