ASP.NET DetailsView changing field display for edit verses insert mode -


I'm for ASP.NET, I use a Vivrndrishy to put the records and editing. For editing mode I do not want to display the primary key field because it should not be changed. To insert mode, I wanted to show the primary key field do because it does not exist and the user it can specify through the drop-down list to ensure that they choose a unique value. TemplateField is used in the DetailsView markup for primary key fields (hence the DropDownList mode to insert).

My problem is that I have to insert mode markup to not display the editing mode to the primary key fields:

  & lt; Asp: TemplateField HeaderText = "name" InsertVisible = "True" Visible = "True" & gt; & Lt; InsertItemTemplate & gt; & Lt; ASP: DropDownList ID = "ddl2NonMembers" runat = "server" width = "155px" Sourceless = "sqlNonMembers" DataTextField = "name" DataValueField = "id_adm" SelectedValue = '& lt;% # bound ( "member_grp")% & gt ; '& Gt; & Lt; / ASP: DropDownList & gt; & Lt; / InsertItemTemplate & gt; & Lt; / ASP: TemplateField & gt; With TemplateField visual = "true", the header displays the text = "name" that always does not want to edit mode. With TemplateField Visible = "False", the field is never displayed, which I do not want for insert mode.  

How can I get a display behavior that I want for embedded chat mode?

Please give advice!

Div class = "post-text" itemprop = "text">

You Check details view mode and see whether it is in edit mode or not. Then you can hide as DropDownList program

  if (myDetailsView.CurrentMode == DetailsViewMode.Edit) {DropDownList ddl2NonMembers = (DropDownList) myDetailsView.FindControl ( "ddl2NonMembers") .; Ddl2NonMembers.Visible = false; }  

Also, you can hide the entire column, but you'll need to know the index of the column. Assuming that the column index # 5 can do something you like:

  if (myDetailsView.CurrentMode == DetailsViewMode.Edit) {myDetailsView.Columns [5] .Visible = false; }  

And finally, you can create a function in the Code-Behind which sees the current value of the DetailsView and specify it in the visible property of their blueprint fields:

  public bool show PKField () {bool result = true; If (myDetailsView.CurrentMode ==ViewMode.Edit) results = False; Return result; }  

and inside your template field:

  & lt; ASP: TemplateField HeaderText = "name" InsertVisible = "true" city = '& lt;% # ShowPKField ()% & gt; '& Gt;  

Comments