Ok - I see.
Please remember to use the code formatting options in your posts (that's the yellow 'code' button at the top of the textarea. It adds code tags to your post. I have updated your question for you, this time.
The way that I would do this is:
1: <deleted> actually didn't need this
2: add another event handler to the gridview for
DataBound
which will occur after the data is bound and the other rows have been added.
3: In the event handler, sum the columns (pseudo code below) and create a gridview footer row
4: add the footer to the gridview rows.
protected void BindGridviewData()
{
string dataId = Request.QueryString["q"];
DataTable scoreGrid = new DataTable();
using (SqlConnection conn = new SqlConnection(connString))
{
using (SqlCommand cmd = new SqlCommand("PROC_DO_Sector_Influencer", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@DO_Ticker", SqlDbType.VarChar, 50).Value = dataId;
SqlDataAdapter da = new SqlDataAdapter(cmd);
conn.Open();
da.Fill(scoreGrid );
conn.Close();
}
}
gridScore.DataSource = ConvertColumnsAsRows(scoreGrid );
gridScore.DataBind();
gridScore.HeaderRow.Visible = false;
}
protected void gridScore_DataBound(object sender, EventArgs e)
{
DataTable dt = gridScore.DataSource as DataTable;
if(dt==null)
return;
int[] footerValues = new int[dt.Columns.Count];
foreach (DataRow row in dt.Rows)
{
for(int x = 0;x<dt.columns.count;x++)>
{
footerValues[x] += int.Parse(row[x].ToString());
}
}
GridViewRow footerRow = gridScore.FooterRow;
footerRow.Cells.Add(new TableHeaderCell
{
Text = @"Totals",
ColumnSpan = 2,
BackColor = Color.FromArgb(0xA7A6AA)
});
foreach (int footerValue in footerValues)
{
System.Web.UI.WebControls.Image image = GetIconFromValue(footerValue);
TableCell cell = new TableCell();
cell.Controls.Add(image);
footerRow.Cells.Add(cell);
}
}
protected void gridScore_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].CssClass = "gridcss";
}
}
public DataTable ConvertColumnsAsRows(DataTable dt)
{
DataTable dtnew = new DataTable();
for (int i = 0; i <= dt.Rows.Count; i++)
{
dtnew.Columns.Add(Convert.ToString(i));
}
for (int j = 0; j < dt.Columns.Count; j++)
{
var dr = dtnew.NewRow();
dr[0] = dt.Columns[j].ToString();
for (int k = 1; k <= dt.Rows.Count; k++)
dr[k] = dt.Rows[k - 1][j];
dtnew.Rows.Add(dr);
}
return dtnew;
}
protected void gridScore_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridViewRow headerRow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell headerCell = new TableCell
{
Text = @"Score Influncers",
ColumnSpan = 2,
BackColor = Color.FromArgb(0xA7A6AA)
};
headerCell.Font.Size = 12;
headerRow.Cells.Add(headerCell);
gridScore.Controls[0].Controls.AddAt(0, headerRow);
}
}