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 6140959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:11:04+00:00 2026-05-23T18:11:04+00:00

Is it possible to get a FormView to automatically default to ReadOnly mode on

  • 0

Is it possible to get a FormView to automatically default to ReadOnly mode on the record that it has just inserted via its InsertItemTemplate? It seems like this would be somethign that should come naturally to a FormView.

  • 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-23T18:11:05+00:00Added an answer on May 23, 2026 at 6:11 pm

    Yes, It is possible.

    I am demonstrating it with the Employee table

    Use the following Sql Server script to create employee tabled named tbemployee

    CREATE TABLE [dbo].[tbemployee](
    [empid] [int] IDENTITY(1,1) NOT NULL,
    [ename] [varchar](50) NULL,
    [eadd] [varchar](50) NULL,
    [esal] [int] NULL,
    [edno] [int] NULL, 
    
    CONSTRAINT [PK_tbemployee] PRIMARY KEY CLUSTERED 
    (
        [empid] ASC
    )
    ) ON [PRIMARY]
    GO
    

    The source code for Inserting record into FormView is shown below:

    FormView.aspx

    <asp:FormView ID="FormView1" runat="server" DataKeyNames="empid" 
            oniteminserting="FormView1_ItemInserting" DefaultMode="Insert"
            onmodechanging="FormView1_ModeChanging">            
            <InsertItemTemplate>
                ename:
                <asp:TextBox ID="txtename" runat="server" Text='<%# Bind("ename") %>' />
                <br />
                eadd:
                <asp:TextBox ID="txteadd" runat="server" Text='<%# Bind("eadd") %>' />
                <br />
                esal:
                <asp:TextBox ID="txtesal" runat="server" Text='<%# Bind("esal") %>' />
                <br />
                edno:
                <asp:TextBox ID="txtedno" runat="server" Text='<%# Bind("edno") %>' />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
            <ItemTemplate>
                empid:
                <asp:Label ID="empidLabel" runat="server" Text='<%# Eval("empid") %>' />
                <br />
                ename:
                <asp:Label ID="enameLabel" runat="server" Text='<%# Bind("ename") %>' />
                <br />
                eadd:
                <asp:Label ID="eaddLabel" runat="server" Text='<%# Bind("eadd") %>' />
                <br />
                esal:
                <asp:Label ID="esalLabel" runat="server" Text='<%# Bind("esal") %>' />
                <br />
                edno:
                <asp:Label ID="ednoLabel" runat="server" Text='<%# Bind("edno") %>' />
                <br />
                <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                    CommandName="New" Text="New" />
            </ItemTemplate>
        </asp:FormView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="Data Source=gts7;Initial Catalog=dbemp14;Integrated Security=True;Pooling=False"             
            ProviderName="System.Data.SqlClient">           
        </asp:SqlDataSource>
    

    and in the Code Behind of FormView.aspx page paste the following code:

    FormView.aspx.cs

    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    
    public partial class _Default : System.Web.UI.Page 
    {
        SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
    
    protected void Page_Load(object sender, EventArgs e)
    {
    
    }
    
    protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
        {
            string ename, eadd,insertqry;
            Int32 esal, edno;
            ename = ((TextBox)(FormView1.FindControl("txtename"))).Text;
            eadd = ((TextBox)(FormView1.FindControl("txtename"))).Text;
            esal = Convert.ToInt32(((TextBox)(FormView1.FindControl("txtesal"))).Text);
            edno = Convert.ToInt32(((TextBox)(FormView1.FindControl("txtedno"))).Text);
    
        insertqry="insert tbemployee(ename,eadd,esal,edno) values(@ename,@eadd,@esal,@edno)";
    
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }
    
        SqlCommand cmd = new SqlCommand(insertqry, con);
        cmd.Parameters.Add("@ename", SqlDbType.VarChar, 50).Value = ename;
        cmd.Parameters.Add("@eadd", SqlDbType.VarChar, 50).Value = eadd;
        cmd.Parameters.Add("@esal", SqlDbType.Int).Value = esal;
        cmd.Parameters.Add("@edno", SqlDbType.Int).Value = edno;
    
        cmd.ExecuteNonQuery();
        cmd.Dispose();
        con.Close();
    
        FormView1.ChangeMode(FormViewMode.ReadOnly);
        formbind();
    }
    
    public void formbind()
    {
        if (FormView1.AllowPaging == true)
        {
            SqlDataAdapter adp = new SqlDataAdapter("select * from tbemployee", con);
            DataSet ds = new DataSet();
            adp.Fill(ds);
    
            Int32 totrecords = ds.Tables[0].Rows.Count;
            Int32 currentpageindex = totrecords - 1;
            FormView1.PageIndex = currentpageindex;
            FormView1.DataSource = ds;
            FormView1.DataBind();
        }
        else
        {
            SqlDataAdapter adp = new SqlDataAdapter("select * from tbemployee where empid in (select isnull(max(empid),0) from tbemployee)", con);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            FormView1.DataSource = ds;
            FormView1.DataBind();
        }
    }
    
    protected void FormView1_ModeChanging(object sender, FormViewModeEventArgs e)
    {
        FormView1.ChangeMode(e.NewMode);
        formbind();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to get notified (without polling, but via an event) when a
Hi I would like to ask if its possible get array with clear data
Possible Duplicate: Get just the Date from grouping in select from DateTime column in
Possible Duplicate: Get the id of a the item that is clicked I have
I have a formview that I select data based on values I get from
Possible Duplicate: Get first day of week in PHP? i have this script that
Possible Duplicate: Get number of checkboxes that are checked in Javascript obj = document.getElementById('myform').elements.length.checked;
Possible Duplicate: Get the Files inside a directory Is there a function that can
Possible Duplicate: Get CVS history for a particular user Is it possible to list
Possible Duplicate: Get all files from VSS for a given date? I need to

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.