473,508 Members | 2,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

change datagrid headers via code

on my web app, i need to display data from a table in a grid. (i know how to
do that). The grid will be populated with data depending on what the user
selects in a drop down box. My question is instead of having 20 grids can i
use only 1 and change the data that should be displayed and the headers via
code, or do I need a seperate grid per choice in the drop down box.
Nov 18 '05 #1
4 2025
Hi,
You can access individual columns using DataGrid.Columns[<col index>]. For
eg, to change the header text of the first column,
DataGrid.Columns[0].HeaderText = "My Col1 Text".

Hope this is what you are looking for.

"IGotYourDotNet" <IG************@discussions.microsoft.com> wrote in message
news:0F**********************************@microsof t.com...
on my web app, i need to display data from a table in a grid. (i know how to
do that). The grid will be populated with data depending on what the user
selects in a drop down box. My question is instead of having 20 grids can i
use only 1 and change the data that should be displayed and the headers via
code, or do I need a seperate grid per choice in the drop down box.
Nov 18 '05 #2
it is but i get this error message when i try to change the first column
header.

Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index

heres my code i'm changing it in

dgStuff.Columns(0).HeaderText = "Cars"
"Shiva" wrote:
Hi,
You can access individual columns using DataGrid.Columns[<col index>]. For
eg, to change the header text of the first column,
DataGrid.Columns[0].HeaderText = "My Col1 Text".

Hope this is what you are looking for.

"IGotYourDotNet" <IG************@discussions.microsoft.com> wrote in message
news:0F**********************************@microsof t.com...
on my web app, i need to display data from a table in a grid. (i know how to
do that). The grid will be populated with data depending on what the user
selects in a drop down box. My question is instead of having 20 grids can i
use only 1 and change the data that should be displayed and the headers via
code, or do I need a seperate grid per choice in the drop down box.

Nov 18 '05 #3
Are you trying to set the header text before you have bound the data to the
grid?

There are no columns in the Columns collection until the databind occurs
unless you are setting the columns up at design time.

Steve

"IGotYourDotNet" <IG************@discussions.microsoft.com> wrote in message
news:F8**********************************@microsof t.com...
it is but i get this error message when i try to change the first column
header.

Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index

heres my code i'm changing it in

dgStuff.Columns(0).HeaderText = "Cars"
"Shiva" wrote:
Hi,
You can access individual columns using DataGrid.Columns[<col index>]. For eg, to change the header text of the first column,
DataGrid.Columns[0].HeaderText = "My Col1 Text".

Hope this is what you are looking for.

"IGotYourDotNet" <IG************@discussions.microsoft.com> wrote in message news:0F**********************************@microsof t.com...
on my web app, i need to display data from a table in a grid. (i know how to do that). The grid will be populated with data depending on what the user selects in a drop down box. My question is instead of having 20 grids can i use only 1 and change the data that should be displayed and the headers via code, or do I need a seperate grid per choice in the drop down box.

Nov 18 '05 #4
As Steve suggested, try it after you did the databinding on the grid.

"IGotYourDotNet" <IG************@discussions.microsoft.com> wrote in message
news:F8**********************************@microsof t.com...
it is but i get this error message when i try to change the first column
header.

Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index

heres my code i'm changing it in

dgStuff.Columns(0).HeaderText = "Cars"
"Shiva" wrote:
Hi,
You can access individual columns using DataGrid.Columns[<col index>]. For
eg, to change the header text of the first column,
DataGrid.Columns[0].HeaderText = "My Col1 Text".

Hope this is what you are looking for.

"IGotYourDotNet" <IG************@discussions.microsoft.com> wrote in message news:0F**********************************@microsof t.com...
on my web app, i need to display data from a table in a grid. (i know how to do that). The grid will be populated with data depending on what the user
selects in a drop down box. My question is instead of having 20 grids can i use only 1 and change the data that should be displayed and the headers via code, or do I need a seperate grid per choice in the drop down box.

Nov 18 '05 #5

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

Similar topics

7
7655
by: Billy Jacobs | last post by:
I am using a datagrid to display some data. I need to create 2 header rows for this grid with columns of varying spans. In html it would be the following. <Table> <tr> <td colspan=8>Official...
3
539
by: sam | last post by:
Hello Group, Havent had luck posting it to microsoft.public.dotnet.framework.aspnet.datagridcontrol group. Excuse me for the cross posting. I have a datagrid which needs to be split into multiple...
5
1645
by: Ben | last post by:
Is there any way to freeze the DataGrid headers so that the headers are always viewable while srolling down? Thanks in advance, Ben!
0
1128
by: Hai Nguyen | last post by:
Below is my code, would anybody please figure out why it did not display any thing. The database did not anything in there yet, what it does is the header field. It just shows me the headers only,...
1
5281
by: Craig Banks | last post by:
If a row of data in a dataset has a lot of columns the row displaying the data in a datagrid will run way off the screen. What I'd like to do is display a row of data over several datagrid rows so...
2
6181
by: gh0st54 | last post by:
hi still working on changing my data grid headers using resource files the thing is i always gat a count of 0 for my datagrid columns count, when will i get the columns count and when should i...
2
1773
by: tshad | last post by:
I have a Datagrid that has no rows in it, but I want the title to show, and they aren't. Is there a way to make them visible even if the Datagrid is empty? Thanks, Tom
1
10222
by: ElenaR | last post by:
I need to figure out how to name my column headers in a DataGrid. In VB6, I could write DataGrid1.Columns(0).Caption = "ID". What is the format for VB.NET? Thanks in Advance!
4
3099
by: cooltech77 | last post by:
Hi, I am trying to build the following functionality in the datagrid. I have a lot of columns in the datagrid which are being populated from the database and the user needs to scroll...
0
7323
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,...
0
7379
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...
1
7038
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...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5625
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,...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
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 ...

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.