473,803 Members | 4,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1146
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.c o.uk> wrote in message
news:d1******** **@bagan.srce.h r...
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 autogeneratecol umns = 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
1739
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. Everything worked perfectly for me in my test application however when I copied and pasted the code accross to my main project something strange started to happen. On the on-click event of the button (cmdExcAdrContinue) the datagrid is populated...
4
2852
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
1246
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 code bellow: Thanks! --------------------------------------- Vilmar Brazão de Oliveira HI-TEC Informática
5
2291
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 collection object -- say, a dictionary. Populating that collection object with custom objects, say, Person. What I really want to see is how to populate the properties of those Person objects from a datasource: instantiate one Person, fill...
4
1906
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 don't see a way to do this through the datagrid properties. I am not using a database connection, I just want to set column headers on the datagrid. I am somewhat new to vb.net. Here is the code I am using. This code works when the...
1
6454
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 MVC-ipmlementation from the JAVA by using the observer-pattern. I used an interface IObservable (AddObserver, RemoveObserver,...). My Model implemented this interface.
0
1035
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 = ButtonColumnType.PushButton; ec.CancelText = "Cancel"; ec.EditText = "Edit"; ec.HeaderText = "Rename";
7
5120
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 text and a set of textboxes.
5
2306
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 like so: Dim column as TemplateColumn = new TemplateColumn() column.HeaderText = "Template Column" column.ItemStyle.Width = Unit.Pixel(width) column.HeaderStyle.Width = Unit.Pixel(width)
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.