By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

change datagrid headers via code

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.