R
Rick Beach
I have the below code to format a cell background color to red in my GridView3. This is from my aspx page in source view.
Below is the Gridview with only the column 12 (zero based) listed:
//the first line is show the correct gridview name only
<asp:GridView ID="GridView3" ...
<asp:BoundField DataField="2B Curr Ld" HeaderText="2B Curr Ld" ReadOnly="True" SortExpression="2B Curr Ld" />
</asp:GridView>
Below is the sub created to change the color when the page loads:
<Sub onload>
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
{
// Check if row is data row, not header, footer etc.
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Get value of twelth column zero based
int CellValue = Convert.ToInt32(e.Row.Cells[12].Text);
// If value is greater of 10, change format
if (CellValue > 10)
{
// Use this syntax to change format of single cell
e.Row.Cells[12].BackColor = System.Drawing.Color.Red;
}
}
}
</Sub>
I am very new to .net and I am not sure if this is in the wrong location, if the programming is actually starting or if the programming itself is incorrect.
I would appreciate any help.
Submitted via EggHeadCafe
Statistics, Probability, Lotteries and Dumb Programmers
http://www.eggheadcafe.com/tutorial...obability-lotteries-and-dumb-programmers.aspx
Below is the Gridview with only the column 12 (zero based) listed:
//the first line is show the correct gridview name only
<asp:GridView ID="GridView3" ...
<asp:BoundField DataField="2B Curr Ld" HeaderText="2B Curr Ld" ReadOnly="True" SortExpression="2B Curr Ld" />
</asp:GridView>
Below is the sub created to change the color when the page loads:
<Sub onload>
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
{
// Check if row is data row, not header, footer etc.
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Get value of twelth column zero based
int CellValue = Convert.ToInt32(e.Row.Cells[12].Text);
// If value is greater of 10, change format
if (CellValue > 10)
{
// Use this syntax to change format of single cell
e.Row.Cells[12].BackColor = System.Drawing.Color.Red;
}
}
}
</Sub>
I am very new to .net and I am not sure if this is in the wrong location, if the programming is actually starting or if the programming itself is incorrect.
I would appreciate any help.
Submitted via EggHeadCafe
Statistics, Probability, Lotteries and Dumb Programmers
http://www.eggheadcafe.com/tutorial...obability-lotteries-and-dumb-programmers.aspx