1

My Question is:

I have a GridView and it contains a column (Button field). Now I want to know on runtime that wheather my Grid contains a Button field or not.

 foreach (DataColumn col in Table.Columns)
                {
                    ButtonField btnfield = new ButtonField();
                    btnfield.ButtonType = ButtonType.Image;

                    if (grid.Columns.Contains(btnfield))
                    {
                        grid.Columns.RemoveAt(grid.Columns.IndexOf(btnfield));
                    }

                }

This code does not work. I want to achieve this task without Row Data Bound.

Regards Zuhaib

Marxist Ali
  • 65
  • 2
  • 11

1 Answers1

1

If i get your question right here is what you got to do:

foreach (GridViewRow row in YourGridView.Rows)
{
    //This should get the control in the cell, you could use FindControl too.
    Control ctrl = row.Cells[columnIndex].Controls[0];
    //Check the control type
    if (ctrl.GetType() == typeof(ButtonField))
    {
    }
}
yahya kh
  • 751
  • 3
  • 11
  • 23