How do I access the value of 'BoundField' in RowDataBound event of gridview?
You can get it by this: string str = e. Row. Cells[CloumnIndexOfYourBoundField].
You need to use gridView. FindControl("controlName"); to get the control in the row.
The RowDataBound event is raised when a data row (represented by a GridViewRow object) is bound to data in the GridView control. This enables you to provide an event-handling method that performs a custom routine, such as modifying the values of the data bound to the row, whenever this event occurs.
Use the following procedure. Drop a GridView control from the toolbox and set the AutoGenerateColumns property to false. Add a Columns Collection (element) to manage the collection of Column fields. Inside the Columns tag, add a column field (BoundField) that displays the value of a field in a data source.
DataRowView drv = (DataRowView)e.Row.DataItem;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (drv["MYCOLNAME"] != DBNull.Value)
{
var val = Convert.ToBoolean(drv["MYCOLNAME"]);
}
}
Just convert to the correct type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With