473,320 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

creating a datagrid...

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)
Nov 19 '05 #1
3 1124
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

"Bad_Kid" <RE*******************@yahoo.co.uk> wrote in message
news:d1**********@bagan.srce.hr...
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)


Nov 19 '05 #2
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
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)


Nov 19 '05 #3
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

"Bad_Kid" wrote:
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)

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stephen | last post by:
I have a really annoying problem with a datagrid. I have an application which populates a datagrid on the onclick event of a button. The datagrid is bound to an ArrayList which holds the values. ...
4
by: Filippo Pandiani | last post by:
I have a grid that shows the file list from a folder. On the postback, how do I get a Dataset from this grid? Thanks, Filippo.
0
by: Vilmar Brazão de Oliveira | last post by:
Hi, I am having err when creating link to each line of grid at LINE 38. My objective in asp.net is: each line can be linked to page with your parameters as VB 5/6, Delphi 5/6/7, etc.... See the...
5
by: | last post by:
Trying to learn about manipulating collections of objects, and populating these objects dynamically from datasources. Could someone post a code sample that shows the following: Instantiating a...
4
by: Jeff | last post by:
I am stuck on trying to generate two columns headers for a datagrid on form load. I can use a datatable as the datasource and get the results I want, but I want to set different column widths and...
1
by: Marcel Hug | last post by:
Hi NG ! I have already written a task about MVC and I tried to get the best informations together. I would like to implement the MVC pattern and it work on the way I did it. At first i know the...
0
by: Ian | last post by:
Hi I have used the following code to essentially late bind an EditCommandColumn to my datagrid in ASP.NET. EditCommandColumn ec = new EditCommandColumn(); ec.ButtonType =...
7
by: =?Utf-8?B?YnJhaW5mdWVsbWVkaWE=?= | last post by:
Can anyone point me in the direction of creating a custom listview item? I guess the other question then - is this possible? I want to create a list of listview items comprised each comprised of...
5
by: tshad | last post by:
I found I can create Template columns dynamically - as long as I don't use objects that need onclick events, such as a LinkButton. Textboxes and Labels work fine. I create the Template columns...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.