Friday, December 15, 2006

ASP.NET DataGrid ItemDataBound Facts

--To Access a ROW OR RECORD IN DATAGRID

--during item databound event--

->when using a DataReader
DbDataRecord rv=(DbDataRecord)e.Item.DataItem;
To check if column is null or not
--if(!rv.isDBNull(2)) 2->column index
To get value of paticular column
--rv.GetValue(2)

->when using a DataSet
DataRowView rv=(DataRowView)e.Item.DataItem;
To check if column is null or not
-- if (!rv.Row.IsNull(2)) 2->column index
To get value of paticular column
--rv.Row.ItemArray.GetValue(1)

--to find control in datagrid and change/modify its property ex Label
in item databound value
Label lblType=new Label();
check if datarow or datarecord "not null" as shown above
then lblType=(Label)e.Item.FindControl("lblID"); where lblID->id of control

once we have control can easily modify property,
ex lblType.visible=false;

No comments: