473,666 Members | 2,111 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 2032
Hi,
You can access individual columns using DataGrid.Column s[<col index>]. For
eg, to change the header text of the first column,
DataGrid.Column s[0].HeaderText = "My Col1 Text".

Hope this is what you are looking for.

"IGotYourDotNet " <IG************ @discussions.mi crosoft.com> wrote in message
news:0F******** *************** ***********@mic rosoft.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.Column s[<col index>]. For
eg, to change the header text of the first column,
DataGrid.Column s[0].HeaderText = "My Col1 Text".

Hope this is what you are looking for.

"IGotYourDotNet " <IG************ @discussions.mi crosoft.com> wrote in message
news:0F******** *************** ***********@mic rosoft.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.mi crosoft.com> wrote in message
news:F8******** *************** ***********@mic rosoft.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.Column s[<col index>]. For eg, to change the header text of the first column,
DataGrid.Column s[0].HeaderText = "My Col1 Text".

Hope this is what you are looking for.

"IGotYourDotNet " <IG************ @discussions.mi crosoft.com> wrote in message news:0F******** *************** ***********@mic rosoft.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.mi crosoft.com> wrote in message
news:F8******** *************** ***********@mic rosoft.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.Column s[<col index>]. For
eg, to change the header text of the first column,
DataGrid.Column s[0].HeaderText = "My Col1 Text".

Hope this is what you are looking for.

"IGotYourDotNet " <IG************ @discussions.mi crosoft.com> wrote in message news:0F******** *************** ***********@mic rosoft.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
7681
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 Impact Summary</td> </tr> <tr> <td colspan=2></td>
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 pages when printing along with headers on every page. I came up with this routine below which adds 2 rows - one with datagrid headers and the other is also a headers which consists other related information. The 2 rows(headers) needs to be...
5
1651
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
1134
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, all the textboxes gone. I want to have at least 5 rows which contain a textbox in each field. I don't know why, please help me ALl textboxes gone .... Thanks public class gridform : System.Web.UI.Page
1
5287
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 the user doesn't have to scroll horizontally. Essentially, I want to wrap a datagrid row (not text in individual columns) with as much control as possible. Make sense? While this seems simple enough on the surface, I can't figure out how to do...
2
6197
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 change the headers ?? thanks private void Page_Load(object sender, System.EventArgs e)
2
1783
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
10231
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
3102
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 horizontally to view these coloumn names. So I want to group them into categories which will fit into a page. A user clicks a category and the category should
0
8356
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
8871
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
8783
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...
0
8640
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
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
6198
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.