PDA

View Full Version : setting table or grid heading in .net


xbabigyrlx
08-08-2006, 04:59 PM
What I need to do is display a table or a datagrid with info generated from a stored procedure. The problem is that the heading of the table or grid can't be hardcoded. The information is generated based on the current month so as the months go by the data and the headings will change to accomodate that... I originally did this in a coldfusion project and need to convert it to asp.net with c#.... Here is the code I used in coldfusion so you can get an idea of what I am trying to do...

<cfoutput>
<table >
<cfloop from="-10" to="1" index="iCount" >
<cfset iMonth = #DateFormat(Now(), "MMM YY")# >
<cfset nMonth = #DateAdd('M', iCount, iMonth)#>
<cfset fMonth = #DateFormat(nMonth, "MMM YY")#>
<td><div align="right"><strong>#fMonth#</strong></div></td>
</cfloop>

<cfloop query = "qCurCharges">
<th scope="row">#qCurFuelSurcharges.FCCode#</div></th>
<td><div align="right">#qCurCharges.Rate10#</div></td>
<td><div align="right">#qCurCharges.Rate9#</div></td>
<td><div align="right">#qCurCharges.Rate8#</div></td>
<td><div align="right">#qCurCharges.Rate7#</div></td>

</cfloop>
</table>
</cfoutput>

How do I do this in asp.net with c#? Thanks for any help in advance.

xbabigyrlx
08-25-2006, 03:19 PM
I figured this out and forgot I was going to post the solution....

protected void GridView1DataBound(object sender, EventArgs e)
{

int iCount = -12;
int colCount = 1;

while (iCount <= 1){
DateTime iMonth = DateTime.Now;
DateTime nMonth = iMonth.AddMonths(iCount);
string fMonth = nMonth.ToString("MMM yy");
GridView1.Columns[colCount].HeaderText = fMonth;
iCount = iCount + 1;
colCount = colCount + 1;
}


}