Brian,
You can certainly create a gridview programmatically. The easiest
example would be to place an empty gridview on a page and then bind
data to it:
(Assuming an already created datatable and GridView columns set to
autogenerate it would only be two lines of code)
GridView1.DataSource = MyDataTable
GridView1.DataBind
Of course the GridView itself may even be created programmatically and
then added to the page or more commonly a placeholder.
Dim GridView1 As New GridView
GridView1.DataSource = MyDataTable
GridView1.DataBind
MyPlaceholder.Controls.Add(GridView1)
You may even specify columns instead of using autogenerate, etc.
default.aspx
<form id="form1" runat="server">
<div>
<asp:GridView id="g" runat="server" ></asp:GridView>
<asp:SqlDataSource id="s" runat="server" ></asp:SqlDataSource>
</div>
</form>
default.aspx.cs listing
//In the Page_Load Function
s.ConnectionString = @"..."
s.SelectCommand = "SELECT * FROM [Classes]";
g.DataSource = s.Select(DataSourceSelectArguments.Empty);
g.AutoGenerateEditButton = true;
g.DataBind();
I've been messing around a bit and while the grid data displays properly,
Clicking on the edit link gives this error.
The GridView 'g' fired event RowEditing which wasn't handled.
As the actutal method which fireing the RowEditing event is dynamically
generated i'm not sure how to go about handling it.
i've tried creating handlers for all of the events attached with editing
and deletion (same errors for those). Any ideas? ( I know its not
completely programmatic but as i'm learning these things i prefer to
figure
out what exectly the asp.net declarative code is interpreted to, and there
don't seem to be many guides on doing thigns programmatically available
either in reference books or online.)