Basically I need help improving the performance of a page full of gridviews to reduce the amount of C# and move as many GridView settings into the ASP Code (not the data itself, that’s bound at run time and needs to stay in the C#).
I’m relatively new to the GridView control and need help moving the settings into the GridView, as the page this code is on will have about 8 or 9 tables.
Here’s my ASP code:
<asp:GridView runat="server" ID="tblBasicProcessingTime"
Caption="Basic Processing Stats" ShowHeader="False">
</asp:GridView>
And my C# Code:
var longestTime = ReportData.OrderByDescending(x => x.TimeSpentProcessing).FirstOrDefault();
var averageTime = ReportData.Average(x => x.TimeSpentProcessing);
var shortestTime = ReportData.OrderBy(x => x.TimeSpentProcessing).FirstOrDefault();
var table = new DataTable();
const string col1Name = "Header";
const string col2Name = "Data";
table.Columns.Add(col1Name);
table.Columns.Add(col2Name);
var row1 = table.NewRow();
row1[col1Name] = "Longest Processing Time";
row1[col2Name] = longestTime.TimeSpentProcessing;
table.Rows.Add(row1);
var row2 = table.NewRow();
row2[col1Name] = "Average Processing Time";
row2[col2Name] = averageTime;
table.Rows.Add(row2);
var row3 = table.NewRow();
row3[col1Name] = "Shortest Processing Time";
row3[col2Name] = shortestTime.TimeSpentProcessing;
table.Rows.Add(row3);
tblBasicProcessingTime.DataSource = table;
tblBasicProcessingTime.DataBind();
Thanks in advance.
This is just a simple demo for gridview databind.
However, my header text is loading from resource file, you can set by yourself, like string “aaa”, “bbb”, “ccc”
In the back end , your code may like this: