AutoGenerateColumns

G

Guest

Hi:

I'm using the DataGrid control with its AutoGenerateColumns property set to
"true". However, I want to programatically change the HeaderText of one its
colums. Nothing I've tried including putting the code in ItemDataBound seem
to be working. Here's what I tried:
Datagrid1.Columns(7).HeaderText = "Reward " & Application("ShowPoints")

I get an "index out of range" exception when this code runs. There are more
than 8 columns in DataGrid1.

Please help.

Thanks,

Jibey
 
E

Eliyahu Goldin

Your only chance to catch column headers for autogenerated columns is the
ItemCreated event.
 
G

Guest

Hi:

That doesn't work either. Here's the code I wrote
Sub DataGrid_ItemCreated(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)
If ddlReport.SelectedValue = "Claim Details" Then
Datagrid1.Columns(7).HeaderText = "Reward " &
Application("ShowPoints")
End If
End Sub

I still get an index out of range error.

Jibey


Eliyahu Goldin said:
Your only chance to catch column headers for autogenerated columns is the
ItemCreated event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Jibey Jacob said:
Hi:

I'm using the DataGrid control with its AutoGenerateColumns property set
to
"true". However, I want to programatically change the HeaderText of one
its
colums. Nothing I've tried including putting the code in ItemDataBound
seem
to be working. Here's what I tried:
Datagrid1.Columns(7).HeaderText = "Reward " & Application("ShowPoints")

I get an "index out of range" exception when this code runs. There are
more
than 8 columns in DataGrid1.

Please help.

Thanks,

Jibey
 
E

Eliyahu Goldin

The Columns doesn't include autogenerated columns.

The whole point of the event is to catch items while they are created. That
is e.Item. You can tell the header items by looking at e.Item.ItemType
property. You can change the header text as e.Item.Cells.Text =
"meHeader";

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Jibey Jacob said:
Hi:

That doesn't work either. Here's the code I wrote
Sub DataGrid_ItemCreated(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)
If ddlReport.SelectedValue = "Claim Details" Then
Datagrid1.Columns(7).HeaderText = "Reward " &
Application("ShowPoints")
End If
End Sub

I still get an index out of range error.

Jibey


Eliyahu Goldin said:
Your only chance to catch column headers for autogenerated columns is the
ItemCreated event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Jibey Jacob said:
Hi:

I'm using the DataGrid control with its AutoGenerateColumns property
set
to
"true". However, I want to programatically change the HeaderText of one
its
colums. Nothing I've tried including putting the code in ItemDataBound
seem
to be working. Here's what I tried:
Datagrid1.Columns(7).HeaderText = "Reward " & Application("ShowPoints")

I get an "index out of range" exception when this code runs. There are
more
than 8 columns in DataGrid1.

Please help.

Thanks,

Jibey
 
G

Guest

That works. However, the sort functionality is disabled. I had set the
AllowSorting property of the grid to true. When I change the names of the
headings this way, they do not have a link button. They just show up as text
that cannot be clicked for sorting. The olther columns where I'm not setting
the headings this way do allow sorting.

Is there a way around this?

Thanks,

Jibey

Eliyahu Goldin said:
The Columns doesn't include autogenerated columns.

The whole point of the event is to catch items while they are created. That
is e.Item. You can tell the header items by looking at e.Item.ItemType
property. You can change the header text as e.Item.Cells.Text =
"meHeader";

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Jibey Jacob said:
Hi:

That doesn't work either. Here's the code I wrote
Sub DataGrid_ItemCreated(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)
If ddlReport.SelectedValue = "Claim Details" Then
Datagrid1.Columns(7).HeaderText = "Reward " &
Application("ShowPoints")
End If
End Sub

I still get an index out of range error.

Jibey


Eliyahu Goldin said:
Your only chance to catch column headers for autogenerated columns is the
ItemCreated event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Hi:

I'm using the DataGrid control with its AutoGenerateColumns property
set
to
"true". However, I want to programatically change the HeaderText of one
its
colums. Nothing I've tried including putting the code in ItemDataBound
seem
to be working. Here's what I tried:
Datagrid1.Columns(7).HeaderText = "Reward " & Application("ShowPoints")

I get an "index out of range" exception when this code runs. There are
more
than 8 columns in DataGrid1.

Please help.

Thanks,

Jibey
 
L

Lukas Kurka

Try something like
((LinkButton)e.Item.Cells.Controls[0]).Text = "foo";

If it doesn't work, place breakpoints there and take a look at
e.Item.Cells, I'm quite sure you will find Controls collection there and
then just play with that. Its horrible, its ugly, but it works.

Lukas

Jibey Jacob said:
That works. However, the sort functionality is disabled. I had set the
AllowSorting property of the grid to true. When I change the names of the
headings this way, they do not have a link button. They just show up as
text
that cannot be clicked for sorting. The olther columns where I'm not
setting
the headings this way do allow sorting.

Is there a way around this?

Thanks,

Jibey

Eliyahu Goldin said:
The Columns doesn't include autogenerated columns.

The whole point of the event is to catch items while they are created.
That
is e.Item. You can tell the header items by looking at e.Item.ItemType
property. You can change the header text as e.Item.Cells.Text =
"meHeader";

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Jibey Jacob said:
Hi:

That doesn't work either. Here's the code I wrote
Sub DataGrid_ItemCreated(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)
If ddlReport.SelectedValue = "Claim Details" Then
Datagrid1.Columns(7).HeaderText = "Reward " &
Application("ShowPoints")
End If
End Sub

I still get an index out of range error.

Jibey


:

Your only chance to catch column headers for autogenerated columns is
the
ItemCreated event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Hi:

I'm using the DataGrid control with its AutoGenerateColumns property
set
to
"true". However, I want to programatically change the HeaderText of
one
its
colums. Nothing I've tried including putting the code in
ItemDataBound
seem
to be working. Here's what I tried:
Datagrid1.Columns(7).HeaderText = "Reward " &
Application("ShowPoints")

I get an "index out of range" exception when this code runs. There
are
more
than 8 columns in DataGrid1.

Please help.

Thanks,

Jibey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top