So on the page I have there is already an increment method in place to add to the count, but I need the option for the user to remove a count. A stored procedure is in place for the increment and Im assuming I can use another for the decrement by using DELETE FROM tablename VALUES etc.

So thats grand if I'm correct. Part im stuck on is the actual code on the aspx.cs page. the code I've got for the incrementation is:

 //method to increment the count of adverts by advert type
        protected void Increment_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                pnlNew.Visible = false;

                //build object to insert occurrance
                Opt a = new Opt();

                a.OptID = Convert.ToInt32(ddlOptID.SelectedValue);
                a.OptRef = Session["OptRef"].ToString();
                a.OptOccurrance = 1;

                try
                {
                    //insert Opt object into db
                    OptManager.InsertOptOccurranceByOptRef(a);

                    //rebind the gridview
                    gridViewOptHistory.DataBind();

                    //reset the Opt occurance label
                    labelOptOccurrances.Text = CountOptByOptRef();

                }
                catch (Exception ex)
                { 

                }
            }
            else
            {
                pnlNew.Visible = true;
            }
        }

        //method to count the occurances of an Opt type
        protected string CountOptBOptRef()
        {
            String one = "None";

            //get count of Options by opt type
            LinkedList<opt> opList = new LinkedList<opt>();
            opList = (LinkedList<opt>)OptManager.GetOptCountByOptRef(Session["OptRef"].ToString());

            String OptType = ddlOptID.SelectedItem.Text;

            //loop through linked list and retrieve count related to selected opt type
            foreach (opt a in opList)
            {
                if (a.OptTypeDescription.ToString() == OptType)
                {
                    one = a.OptOccurrance.ToString();
                }
            }

            return one;

        }

This code is used for the user to select the link to "Add an occurrance" this code then stores the count. However I need to do the opposite and remove a count. What changes would I need to make to the decrement code I have to write?

Any help would be great.

Member Avatar for LastMitch

However I need to do the opposite and remove a count. What changes would I need to make to the decrement code I have to write?

You could try something like this:

a.OptOccurrance = a.OptOccurrance - 1;

This will be your db:

 var dba = from a in OptManager.InsertOptOccurranceByOptRef where a.OptID == OptID select a; dba[OptRef].a.OptOccurrance;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.