views:

152

answers:

1

This is driving me nuts.

I have the following code that, when a button is clicked, a gridview will be populated with data based on the number a client enters into a text box (tbxHowMany).

 protected void btnDisplayTopReport_Click(object sender, EventArgs e)
    {
      if (radPa.Checked)       
      {

            CompleteWeightsDataContext db = new CompleteWeightsDataContext
            int max = 0;
            if (int.TryParse(tbxHowMany.Text, out max))
            {
                var queryPa = db.tblOnlineReportingCOMPLETEWeights
                    .Where (x => x.MaterialLevel == "Primary" && x.MaterialText == "Paper")
                    .OrderByDescending (x => x.ProductPercentage).Take(max);

                GridView1.DataSourceID = "queryPa";
                GridView1.DataBind();
            }
        }
       else if (radGl.Checked)
         {
              CompleteWeightsDataContext db = new CompleteWeightsDataContext
            int max = 0;
            if (int.TryParse(tbxHowMany.Text, out max))
            {
                var queryGl = db.tblOnlineReportingCOMPLETEWeights
                    .Where (x => x.MaterialLevel == "Primary" && x.MaterialText == "Glass")
                    .OrderByDescending (x => x.ProductPercentage).Take(max);

                GridView1.DataSourceID = "queryGl";
                GridView1.DataBind();
            }
         }
       }

Unfortunately I keep on getting "a new expression requires (),[], etc" on the first int.

Can someone explain to me the error and/or what I have done wrong and how I can work around this?

Apologies for the, most likely dim, question.

+6  A: 

Your error is actually on the line before (it shows up as on that line, because the line before isn't properly terminated, so int max... is where the compiler first realizes something's gone wrong.

The error is here:

CompleteWeightsDataContext db = new CompleteWeightsDataContext

It should be:

CompleteWeightsDataContext db = new CompleteWeightsDataContext();
David Hedlund
I can't believe I missed that! I think I need some lunch!Thanks for the fresh pair of eyes David.
MrDean