When the item is bind to the DataGrid control, the ItemDatabase event will be triggered. This event provides the last chance to access the data item before the client displays the data item. With DataGrid's itemDatabase, we can easily implement some practical features.
Private void DataGrid1_itemdatabase (Object Sender, DataGriditeMeventArgs E)
{
IF (E.Item.ItemType == ListItemType.Item || E.Item.ItemType == ListItemType.alternatingItem)
{
DataRowView DRV = (DATAROWVIEW) E.Item.DataItem;
/ / Set the serial number of each row
INT Num = E.Item.itemindex 1;
E.Item.cells [0] .Text = Num.tostring ();
// "Sex" field is in the database
0
"
with"
1
"
Stored, now in "men" and "women" to users
INT sex = convert.toint32 (DRV ["fsex"]);
E.Item.cells [2] .Text = (sex == 0? "male": "female");
// Bind "Marriage" field to Checkbox
INT Married = Convert.Toint32 (DRV ["FMarried"]);
Checkbox Chk = (Checkbox) E.Item.FindControl ("CheckBox1");
Chk.checked = (married == 0? false: true);
}
}
Results as shown below: