creating a datagrid...

  • Thread starter Thread starter Bad_Kid
  • Start date Start date
B

Bad_Kid

How can I dynamicly create a datagrid?
(first I read a datatable from a database, see how many atributes does it
have (n) and then build a datagrid with n columns...)???

(c#, asp.net)
 
Dynamically create a datagrid in ASP.net using C#

Create a dynamic ASP.Net datagrid control and columns using c# code. This
example demonstrates how to generate a datagrid control and datagrid columns
on the fly in the code behind file based on the results of a SQL Query

http://odetocode.com/Articles/218.aspx
 
That's the beauty of ASP.NET: It is a server side object model:

DataGrid dg = new DataGrid();
BoundColumn col = new BoundColumn();
col.DataField = "SomeColumn";
col.HeaderText = "Some Header";
dg.Columns.Add(col)

dg.DataSource = ds;
dg.DataBind();

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
A co-worker was doing something similar, where the grid shows different
results in different situations. looping through the dataview columns and
adding datagrid columns. It turned out to be an easier solution to let the
datagrid do it with autogeneratecolumns = true. You might have to hide
certain fields, but that will probably be easier than hard-coding the columns
by hand.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top