Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 934241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:58:00+00:00 2026-05-15T20:58:00+00:00

For ASP.NET, I’m using a DetailsView for insert and edit of a record. For

  • 0

For ASP.NET, I’m using a DetailsView for insert and edit of a record. For edit mode I don’t want to display the primary key field because it should not be changed. For insert mode, I want to display the primary key field because it doesn’t exist and the user can specify it via a DropDownList that insures they will pick an unique value. A TemplateField is used in the DetailsView markup for the primary key field (hence the DropDownList for insert mode).

My problem is that I cannot get the primary key field to not display for edit mode and to display for insert mode. In the markup I have:

<asp:TemplateField HeaderText="name" InsertVisible="True" Visible="True">
    <InsertItemTemplate>
        <asp:DropDownList ID="ddl2NonMembers" runat="server"
            Width="155px" 
            Sourceless="sqlNonMembers" 
            DataTextField="name" 
            DataValueField="id_adm" 
            SelectedValue='<%# Bind("member_grp") %>'>
        </asp:DropDownList>
    </InsertItemTemplate>
</asp:TemplateField>

With the TemplateField Visible=”True”, the HeaderText=”name” always displays which I don’t want for edit mode. With the TemplateField Visible=”False”, the field never displays which I don’t want for insert mode.

How can I achieve the display behavior I want for insert verses edit mode. I’m fine with changing some property programmatically rather than relying an a pure markup approach, but I can’t figure out the solution.

Please advise!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:58:01+00:00Added an answer on May 15, 2026 at 8:58 pm

    you can test the Details View Mode and see if it’s in -Edit- mode. You can then hide the DropDownList programmatically.

    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 that column. Assuming column index is #5 you can do something like:

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

    And finally, you can create a function in Code-Behind which checks the current value of the DetailsView and assign it to the Visible property of your Template field:

    public bool showPKField() {
        bool result = true;
        if(myDetailsView.CurrentMode == DetailsViewMode.Edit)
            result = false;
        return result;
    }
    

    And inside your Template Field:

    <asp:TemplateField HeaderText="name" InsertVisible="True" Visible='<%# showPKField() %>'>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ASP.NET server-side controls postback to their own page. This makes cases where you want
ASP.Net Html.TextBoxFor (and the other XxxxxFor editor helper methods) default to rendering a field
ASP.NET For each appSetting I use, I want to specify a value that will
ASP.NET 4.0 I've checked that using both or control (which is a wrap of
In ASP.NET MVC 3, I've declared an ajax form like this: @using (Ajax.BeginForm(SaveRegistrationConfirmationRequest, null,
ASP.NET MVC has been discussed on this forum a few times. I'm about to
ASP.NET 2.0 provides the ClientScript.RegisterClientScriptBlock() method for registering JavaScript in an ASP.NET Page. The
ASP.NET 1.1 - I have a DataGrid on an ASPX page that is databound
ASP.Net: In code-behind I can simulate <%# Eval(Property)%> with a call to DataBinder.Eval(myObject,Property); How
ASP.Net 3.5 running under IIS 7 doesn't seem to allow this out of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.