0

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.

2
Contributors
1
Reply
5
Views
4 Years
Discussion Span
Last Post by LastMitch
0

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;

Edited by LastMitch: grammer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.