WebGrid provides FormatConditions feature to help you create your
own format for the information/data in WebGrid.
In this topic, you will learn how to create FormatConditions in specific
row and cell using table Customers from NorthWind database.
To create FormatConditions in a specific row and cell
- Drag WebGrid control from Toolbox to the WebForm.
- Switch to code-behind and Add InitializeLayout server
side event:
using System.Drawing;
using ISNet.WebUI.WebGrid;
private void WebGrid1_InitializeLayout(object sender, ISNet.WebUI.WebGrid.LayoutEventArgs e)
{
//specific row
WebGridFormatCondition a = new WebGridFormatCondition();
a.ColumnMember = "Country";
a.ConditionText = "UK";
a.Name = "Format1";
a.FormatStyle.ForeColor = Color.Red;
a.TargetObject = ISNet.WebUI.WebGrid.TargetObjectType.Row;
//specific Cell
WebGridFormatCondition b = new WebGridFormatCondition();
b.ColumnMember = "City";
b.ConditionText = "Madrid";
b.Name = "Format2";
b.TargetColumnMember = "City";
b.FormatStyle.Font.Bold = true;
b.TargetObject = ISNet.WebUI.WebGrid.TargetObjectType.Cell;
WebGrid1.RootTable.FormatConditions.Add(a);
WebGrid1.RootTable.FormatConditions.Add(b);
}
|
-
Run the project. The result will look like following.
|
Please note that if you are using RetrieveStructure, then you need to put the above
codes in PrepareDataBinding.
|