Yes,
I could do this, it would stop the blowup, but I would never be able to set
the width of column 2.
When it renders there are 3 columns, but there does not seem to be an event
that I can use where the control has been filled and it contains the columns.
In ther mean time I have used a normal table to render the data. Code is no
more complex and it works!
Mike Parris
"David Wier" wrote:
> What about surrounding your statement with an if/then - so that if the
> column count is larger than 0, set the width
>
> --
> David Wier
> MVP/ASPInsider
> http://aspnet101.com
> http://aspexpress.com
>
>
>
> "Mike Parris" <> wrote in message
> news:A52309C4-530C-42B4-86C2-...
> > I am trying to set the width of one of the columns of an asp.net 2.0
> Gridview
> > control.
> >
> > I am using a line -
> > MyGridview.Columns[2].ItemStyle.Width = Unit.Percentage(40);
> >
> > The problem is that there are no columns in the gridview so this line
> "blows
> > up".
> >
> > I am binding the gridview to data in code in the Page_load event. The
> > problem seems to be that I am trying to set the width before the creation
> of
> > the control is complete. All the examples I have seen, bind the control
> > directly to a database table/query and I presume that the control is then
> > populated earlier.
> >
> > I have triedall the events in the page and the control, but without
> success.
> >
> > Any ideas on what I am doing wrong, or how to achieve this?
> >
> > Mike parris
>
>
>