Color Rows in Enterprise Portal AxGridView
3. August 2011 Leave a comment
- Create a new display method webBackgroundColor at InventTable
public display Color webBackgroundColor()
{;
switch(this.ItemType)
{
case ItemType::BOM: return "Red";
case ItemType::Item: return "Green";
case ItemType::Service: return "Blue";
default: return "White";
}
} - Create a new Dataset and add InventTable as DataSource
- Create or open a new Dynamcis Ax web project in Visual Studio
- Create or open an AxWebUserControl and add an AxDataSource using InventTable data set from AX
- Add an AxGridView and link it with the AxDataSource
- Add webBackroungColor**, ItemId and ItemName to the grid
- Select the AxGridView, change to events and modify the RowDataBound event
protected void AxGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
string axColor = e.Row.Cells[0].Text.ToLower();
if(axColor.Equals("red"))
e.Row.BackColor = System.Drawing.Color.Red;
else if(axColor.Equals("green"))
e.Row.BackColor = System.Drawing.Color.Green;
else if(axColor.Equals("blue"))
e.Row.BackColor = System.Drawing.Color.Blue;
} - Load the user control in an enterprise portal site
Use an Extended Datatype (Color instead of str) for the display method, otherwise you may experience strange behaviour in your ASP.NET application.