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

  • SEARCH
  • Home
  • 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 8349591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:03:03+00:00 2026-06-09T08:03:03+00:00

I had posted a thread a while back about avoiding adding blank rows into

  • 0

I had posted a thread a while back about avoiding adding blank rows into the database. Before when something was to click add row it would automatically add a blank row into the database regardless if the user canceled the new row. I figured it out but now came to a new issue. If the user decides to reload the page(F5) while editing the new row, it will add a blank row into the database, thats a no no for my situation. Can anyone help me figure out how to avoid that?

Below is my insert code:

protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName == "Insert") //- this is needed to explain that the INSERT command will only work when INSERT is clicked
        {
            gv.DataBind();

            DataTable d = dbcon.GetDataTable("SELECT * FROM CIS.CIS_TRANS ORDER BY ID DESC", "ProjectCISConnectionString");

            string transCode = "", fundCode = "", BSA_CD = "", DP_TYPE = "";

            if (d.Rows.Count > 0)
            {
                transCode = d.Rows[0]["TRANS_CD"].ToString();
                fundCode = d.Rows[0]["FUND_CD"].ToString();
                BSA_CD = d.Rows[0]["BSA_CD"].ToString();
                DP_TYPE = d.Rows[0]["DP_TYPE"].ToString();

                if (transCode.Trim().Length > 0)
                {
                    dbcon.Execute("INSERT INTO CIS.CIS_TRANS (ID,TRANS_CD) VALUES(CIS.S_CIS_TRANS.nextval,'')", "ProjectCISConnectionString");

                    gv.DataBind();
                }
            }

            gv.EditIndex = gv.Rows.Count - 1;

        }
        else if (e.CommandName == "Cancel")
        {
            DataTable d = dbcon.GetDataTable("SELECT * FROM CIS.CIS_TRANS ORDER BY ID DESC", "ProjectCISConnectionString");

            string transCode = "";

            if (d.Rows.Count > 0)
            {
                transCode = d.Rows[0]["TRANS_CD"].ToString();

                if (transCode.Trim().Length == 0)
                {
                    dbcon.Execute(string.Format("DELETE CIS.CIS_TRANS WHERE ID = '{0}'", d.Rows[0]["ID"]), "ProjectCISConnectionString");

                    gv.DataBind();
                }
            }


        }
    }
  • 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-06-09T08:03:05+00:00Added an answer on June 9, 2026 at 8:03 am

    If you want to avoid inserting blank row by the user, you need validators. Add RequiredFieldValidator to the insert template:

    <asp:RequiredFieldValidator runat="server" ID="valFieldName"
    < ControlToValidate="txtFieldName" ErrorMessage="FieldName is missing" />
    

    In your method check if Page.IsValid == true before you insert to the database.

    EDIT:
    If you want to avoid postbacks completely, you can insert the whole grid into an UpdatePanel:

    <asp:UpdatePanel>
        <ContentTemplate>
            <asp:GrdiView>
            ....
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>
    

    Now when the user hits F5 he just reload the page again and not posting back an insert command.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had posted this question on MSDN Forum http://social.msdn.microsoft.com/Forums/en/vsreportcontrols/thread/f00e3406-354d-4f54-acce-7b7f0ad4c90f But I am not getting
I had recently posted someone about populating a JTable, which is now fully functional.
[EDIT] Alright, I edited this post since the code I posted back then had
I had posted another question earlier about deployment with Passenger. That problem turned out
I have posted on this topic before, but as yet I have not had
I had posted the code before but had asked it differently as I didn't
I had posted this earlier on Stack Overflow, but couldn't get a positive result.
I had posted one question earlier jQuery inconsistency in setting readonly attribute in IE-8
I had posted a question in regards to this code. I found that JTextArea
I posted another one on this,, but i had to edit it really much...

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.