GridView Utilities in C#
GetColumnIndexByHeaderText
// ---- GetColumnIndexByHeaderText ----------------------------------
//
// pass in a GridView and a Column's Header Text
// returns index of the column if found
// returns -1 if not found
static public int GetColumnIndexByHeaderText(GridView aGridView, String ColumnText)
{
TableCell Cell;
for (int Index = 0; Index < aGridView.HeaderRow.Cells.Count; Index++)
{
Cell = aGridView.HeaderRow.Cells[Index];
if (Cell.Text.ToString() == ColumnText)
return Index;
}
return -1;
}
GetColumnIndexByDBName
// ---- GetColumnIndexByDBName ----------------------------------
//
// pass in a GridView and a database field name
// returns index of the bound column if found
// returns -1 if not found
static public int GetColumnIndexByDBName(GridView aGridView, String ColumnText)
{
System.Web.UI.WebControls.BoundField DataColumn;
for (int Index = 0; Index < aGridView.Columns.Count; Index++)
{
DataColumn = aGridView.Columns[Index] as System.Web.UI.WebControls.BoundField;
if (DataColumn != null)
{
if (DataColumn.DataField == ColumnText)
return Index;
}
}
return -1;
}
Revision number 1, Saturday, February 23, 2008 7:19:50 PM by
This is not the most up to date version of this article. The most recent version can be found here.
You must Login to comment.
|
Sat, Jun 14, 2008 6:10 AM
by motin_h
|
good
|
|
Fri, Aug 8, 2008 2:18 AM
by pnv.ravikiran
|
its helpful
|