Data Gridview formating :
public int i = 0;
protected void gvjobsCategory_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (i % 2 == 0)
{
e.Row.CssClass = "job_a"; ;
}
else { e.Row.CssClass = "job_b"; ;}
i++;
}
productsGridView_RowDataBound Event Handler (C#)
void productsGridView_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// determine the value of the UnitsInStock field
int unitsInStock =
Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,
"UnitsInStock"));
if (unitsInStock == 0)
// color the background of the row yellow
e.Row.BackColor = Color.Yellow;
}
}
Data List formating :
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
// Retrieve the Label control in the current DataListItem.
Label PriceLabel = (Label)e.Item.FindControl("Label1");
// Format the value as currency and redisplay it in the DataList.
PriceLabel.CssClass = "job_a";
}
No comments:
Post a Comment