>I'm running into a thing with a data edit WebForm trying to set a column's ReadOnly property.
>
>Data is returned from SQL into a DataSet
>
>GridView is defined as follows
>
> asp:GridView ID="GV1" runat="server" AutoGenerateEditButton="True"
> CellPadding="10" CellSpacing="10" BorderStyle="Solid"
> HorizontalAlign="Center" Caption="DashBoard Configuration Settings"
> CaptionAlign="Top">
> EditRowStyle BackColor="#99CCFF" />
> /asp:GridView>
>
>GridView GV1 is handled as follows
>
>GV1.DataSource = GVSet;
>GV1.DataBind()
>
>The data displays in a grid, as one would expect, but when I get the ColumnIndex of the column that should be ReadOnly and then try to set it with
>((BoundField)GV1.Columns[ColIndx]).ReadOnly = true;
>
>I get an "index out of bounds" error because GV1.Columns.Count = 0
>
>What am I missing, besides a deep and abiding understanding of c#?
The markup isn't valid but I assume that's just a typo (or UT rendering).
IAC it looks as if you have AutoGenerateColumns = True (the default)
See the doc on this :
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.autogeneratecolumns(v=vs.110).aspxSnip: " Automatically generated bound column fields are not added to the Columns collection."
You will probably need to add the columns explicitly in code or markup.
If you use the GridView Tasks popup in the designer to 'Choose data source' it will automatically add the columns to the Gridview markup.
You can then add the ReadOnly attribute to the relevant column in markup or, as currently, in code