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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:28:37+00:00 2026-05-20T06:28:37+00:00

I am using the following code to output data from a number of tables

  • 0

I am using the following code to output data from a number of tables in my database to an excel document.

Protected void btnExcelExport_Click(object sender, EventArgs e)
{

string strQuery = "SELECT s.Story, s.StoryCategoryID, CONVERT(VARCHAR(10), 
s.CreationDate, 103) AS CreationDate, m.CompanyRole, af.Name FROM Story s INNER JOIN    
ProjectIterationMember pm ON pm.ProjectIterationMemberID = s.ProjectIterationMemberID 
INNER JOIN Iterations i ON i.ProjectIterationID = pm.ProjectIterationID INNER JOIN 
Member m ON m.MemberID = pm.MemberID INNER JOIN ProjectStoryFactors psf ON psf.StoryID = 
s.StoryID INNER JOIN AgileFactors af ON af.AgileFactorID = psf.AgileFactorID WHERE 
i.ProjectID = '" + proj_id + "'";

SqlCommand cmd = new SqlCommand(strQuery);
DataTable dt = GetData(cmd);

GridView GridView1 = new GridView();
GridView1.AllowPaging = false;
GridView1.DataSource = dt;
GridView1.DataBind();

Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition","attachment;filename=RetroCloud" +  
DateTime.Now.Ticks + ".xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);

for (int i = 0; i < GridView1.Rows.Count; i++)
{

   GridView1.Rows[i].Attributes.Add("class", "textmode");
}
GridView1.RenderControl(hw);

string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}

The output is as follows:

Story | StoryCategoryID | CreationDate | CompanyRole | Name

negative iii | 1 | 21/02/2011 | Business Analyst | Project Duration
negative iii | 1 | 21/02/2011 | Business Analyst | Team Size
negative iii | 1 | 21/02/2011 | Business Analyst | Process
negative ccc | 1 | 22/02/2011 | Admin | Workspace Layout
negative ccc | 1 | 22/02/2011 | Admin | Organisational and Reporting Structure
negative ccc | 1 | 22/02/2011 | Admin | Process

What I would like to do is 3 things. Many thanks for your help!

1) Change the header names which are clearly coming from the database fields (ie. from StoryCategoryID to Story Type),
2) For StoryCategoryID, if 1 is retrieved – display ‘Negative’ and if 0 is retrieved – display ‘Positive’ instead.
3) Have the output in the following format:

Story | Story Type | Creation Date | Company Role | Tag 1 | Tag 2 | Tag 3

negative iii | 1 | 21/02/2011 | Business Analyst | Project Duration | Team Size | Process
negative ccc | 1 | 22/02/2011 | Admin | Workspace Layout | Organisational | Process
  • 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-05-20T06:28:37+00:00Added an answer on May 20, 2026 at 6:28 am

    You can modify the column names of the data table. Use foreach(DataColumn col in dt.Columns) then use col.ColumnName

    You can access and modify the data for the specific column for your criteria using (Convert.ToInt16(col[n]) != 1)? "Positive" : "Negative" inside a loop. Use dt.Rows.Count for the loop’s condition.

    Hope this helps.

    You can use this inside the foreach loop:

    if (col.ColumnName == "StoryCategoryId") //Or "Story Type"
    for(int rowCount = 0; rowCount < table.Rows.Count; rowCount++)
    {
        col[rowCount] = (Convert.ToInt16(col[rowCount]) == 0) ? "Positive" : "Negative";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using following code but cannot return data from MySQL. This is the output:
Im using the following code to output all the nodes from the xml shown.
I am using the following code to export a dataset from c# to excel.
Iam using Zend RestController to output student data (from database) in xml format. Iam
im using the following code to output an array $values = array(); foreach ($album
I'm using following peace of code to output an array: echo ======output without array_unique=====;
I am using following code to design my home page. The output (as shown
I'm using the following code to read an RSS feed and output the results.
I have the following code which outputs an object to an XML file: using
I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>

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.