Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Difference between DataBind() and BoundField
Message
From
15/08/2014 05:18:23
 
 
To
14/08/2014 16:54:59
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 5.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01605741
Message ID:
01605756
Views:
36
>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).aspx
Snip: " 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
Previous
Reply
Map
View

Click here to load this message in the networking platform