Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In an asp.net gridview how do I access a BoundField in the RowDataBound event?

How do I access the value of 'BoundField' in RowDataBound event of gridview?

like image 748
Rauf Avatar asked Mar 23 '11 12:03

Rauf


People also ask

Where is BoundField of GridView in RowDataBound?

You can get it by this: string str = e. Row. Cells[CloumnIndexOfYourBoundField].

How can get GridView column value in RowDataBound?

You need to use gridView. FindControl("controlName"); to get the control in the row.

What is RowDataBound event in GridView?

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.

How use RowDataBound event in GridView in VB net?

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.


1 Answers

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.

like image 59
RubbleFord Avatar answered Nov 29 '22 17:11

RubbleFord