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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:20:36+00:00 2026-06-10T19:20:36+00:00

I took some code for displaying the content of a sharepoint 2010 list in

  • 0

I took some code for displaying the content of a sharepoint 2010 list in a webpart based on a CAML query and modified it to display the same thing from two lists instead of one in a table. Now I want to further modify the code in order to get the number of incomplete tasks across both lists. to do that I added counters to the loops that populate the table and stored the result in another variable c. Now, the table is populated fine and does what i want it to do, but the value of the variable c is not displayed… can anyone help? I’ll be really thankfull.
Here is the code:

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SharePoint365.WebParts.OutstandingTasks
{
  [ToolboxItemAttribute(false)]
  public class OutstandingTasks : WebPart
  {
    int a; // HERE (1)
    int b; // HERE (1)
    int c; // HERE (1)
    protected override void CreateChildControls()
    {
      /*int a;
      int b;
      int c;*/
      SPList taskList = SPContext.Current.Web.Lists["test list 1"];
      SPList taskList1 = SPContext.Current.Web.Lists["test list 2"];

      SPQuery query = new SPQuery();
      query.Query = "<Where><Neq><FieldRef Name='Status' />";
                   +"<Value Type='Text'>Completed</Value></Neq></Where>";
      query.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='Status'/>";

      SPListItemCollection tasks = taskList.GetItems(query);
      SPListItemCollection tasks1 = taskList1.GetItems(query);
      string htmlTable = "<table border='1'>";  
      htmlTable += "<tr><td>Title</td><td>Status</td></tr>";  

      foreach (SPListItem aTask in tasks)  
      {  
        htmlTable += string.Format("<tr><td>{0}</td><td>{1}</td></tr>",
                       aTask["Title"], aTask["Status"]);
        a++;  // HERE (2)
      }
      foreach (SPListItem aTask in tasks1)
      {
        htmlTable += string.Format("<tr><td>{0}</td><td>{1}</td></tr>",
                       aTask["Title"], aTask["Status"]);
        b++; // HERE (3)
      }

      htmlTable += "</table>";  

      c = a + b;            // HERE (4)
      Console.WriteLine(c); // HERE (4)

      LiteralControl tableControl = new LiteralControl(htmlTable);  
      this.Controls.Add(tableControl); 
    }
  }
}
  • 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-10T19:20:37+00:00Added an answer on June 10, 2026 at 7:20 pm

    You cant use Console.WriteLine to display c. You need to use a LiteralControl like you do with your other strings:

    c = a + b;
    LiteralControl totals = new LiteralControl(c.ToString());
    this.Controls.Add(totals);  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I took some code here: Check if role consists of particular user in DB?
So, I took some code from this Microsoft provided Example which allows me to
I was playing around with some JavaScript code and found that when I took
I took some code from my C# Windows form app which uses the Application
So I took some php code and turned it into a calendar with a
Recently I took a look at some code I'd committed to our version control
Recently, i took ownership of some c++ code. I am going to maintain this
I took some code from some questions here in SO as well as some
I recently took some code from Delphi 2007 and upgraded it to Delphi 2009.
I took some sample code to create a drop down menu from this website:

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.