Hi Michael,
(1) That's right, if AutoGenerateColumns=False, you will need to manually
add all columns. You can do it declaratively in ASPX:
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="au_id"
DataSourceID="SqlDataSource1" OnDataBound="GridView1_DataBound"
OnDataBinding="GridView1_DataBinding">
<Columns>
<asp:BoundField DataField="au_id" HeaderText="au_id"
ReadOnly="True" SortExpression="au_id" />
<asp:BoundField DataField="au_lname" HeaderText="au_lname"
SortExpression="au_lname" />
</Columns>
</asp:GridView>
or you can add at runtime, in either case, you need to know the DataField
name ("au_id" and "au_lname" in above example).
It's possible to duplicate the functionality of how GridView's
AutoGenerateColumns does, however, it's much complicated and I don't think
it's worth the effort doing this: the GridView needs to support various
data source such as DataSource controls (ObjectDataSource, SqlDataSource,
etc.) and IEnumerable data, you can take a look at GridView's code using
Reflector (
http://www.aisto.com/roeder/dotnet/) if you're interested.
(2) Yes one field is a data bound field, just like above declarative
example shows.
As I explained above, I think if you need to set the
AutoGenerateColumns=True, then I suggest you create a customized GridView
to add your custom columns; if you set AutoGenrateColumns=False, then you
need to manually setup those columns in ASPX or code, but you need to know
the data field names.
Hope this helps.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.