Howdy All,
I am wondering if there is a way to find the column index by the header
name. What I am trying to get away from is using a hardcoded number in
the ItemDataBound event. Something like this:
private void grdTestScores_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DataRowView drvData = (DataRowView)e.Item.DataItem;
Button btnDelete;
if ((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
btnDelete = (Button)e.Item.Cells[16].Controls[0];
if (btnDelete.CommandName == "Delete")
{
btnDelete.Attributes.Ad("onclick", "return ConfirmDelete();");
}
}
...
I don't want to hardcode the column number 16 in the above example.
Thanks in advance.
dbl
Eliyahu Goldin - 19 Jul 2005 09:39 GMT
If the columns are not auto-generated, you can use datagrid Columns
collection. Write a utility function that will take a column name as a
parameter, loop through Columns collection, find a column with matching
name, get it's index and return Cells element with the same index.
Eliyahu
> Howdy All,
>
[quoted text clipped - 26 lines]
>
> dbl