How to change header captions

M

Moshe Pack

How can I change header captions when working with a bound DataGrid in
ASP.Net? I am looking for a way to do this without involving the SQL.

Thank you.
 
E

Eliyahu Goldin

An example:

<asp:BoundColumn DataField="Description" HeaderText="Another
Text"></asp:BoundColumn>

Eliyahu
 
E

Eliyahu Goldin

Yes Moshe, you can get to header captions from datagrid Columns collection:

myGrid.Columns.HeaderText = "Another Text";

Note that automatically generated columns are not added to the Columns
collection.

Eliyahu
 
M

Moshe Pack

Eliyahu,

If I generate columns automatically (AutoGenerateColumns = True), is there
anything I can do to change the header text other than to create column
aliases in the SQL?

Thanks,
Moshe.

Eliyahu Goldin said:
Yes Moshe, you can get to header captions from datagrid Columns collection:

myGrid.Columns.HeaderText = "Another Text";

Note that automatically generated columns are not added to the Columns
collection.

Eliyahu

Moshe Pack said:
Eliyahu,

Do you have an idea how to do with code-behind?

Thanks,
Moshe.
 
E

Eliyahu Goldin

Moshe,

You can try doing this in ItemCreated event. Something like that:

if (e.Item.ItemType != ListItemType.Header)
return;

foreach (TableCell cell in e.Item.Cells)
{
switch (cell.Text)
{
case "Description":
cell.Text = "Another Text";
break;
...
}
}

Eliyahu

Moshe Pack said:
Eliyahu,

If I generate columns automatically (AutoGenerateColumns = True), is there
anything I can do to change the header text other than to create column
aliases in the SQL?

Thanks,
Moshe.

Eliyahu Goldin said:
Yes Moshe, you can get to header captions from datagrid Columns collection:

myGrid.Columns.HeaderText = "Another Text";

Note that automatically generated columns are not added to the Columns
collection.

Eliyahu

Moshe Pack said:
Eliyahu,

Do you have an idea how to do with code-behind?

Thanks,
Moshe.

:

An example:

<asp:BoundColumn DataField="Description" HeaderText="Another
Text"></asp:BoundColumn>

Eliyahu

How can I change header captions when working with a bound DataGrid in
ASP.Net? I am looking for a way to do this without involving the SQL.

Thank you.
 
M

Moshe Pack

Eliyahu,

In the ItemCreated event, the Text property for all table cells contains an
empty string.

In the ItemDataBound event, the Text property is indeed filled in for data
cells, but is blank for header cells.

Any other ideas?

Thanks a lot,
Moshe.

Eliyahu Goldin said:
Moshe,

You can try doing this in ItemCreated event. Something like that:

if (e.Item.ItemType != ListItemType.Header)
return;

foreach (TableCell cell in e.Item.Cells)
{
switch (cell.Text)
{
case "Description":
cell.Text = "Another Text";
break;
...
}
}

Eliyahu

Moshe Pack said:
Eliyahu,

If I generate columns automatically (AutoGenerateColumns = True), is there
anything I can do to change the header text other than to create column
aliases in the SQL?

Thanks,
Moshe.

Eliyahu Goldin said:
Yes Moshe, you can get to header captions from datagrid Columns collection:

myGrid.Columns.HeaderText = "Another Text";

Note that automatically generated columns are not added to the Columns
collection.

Eliyahu

Eliyahu,

Do you have an idea how to do with code-behind?

Thanks,
Moshe.

:

An example:

<asp:BoundColumn DataField="Description" HeaderText="Another
Text"></asp:BoundColumn>

Eliyahu

How can I change header captions when working with a bound DataGrid in
ASP.Net? I am looking for a way to do this without involving the SQL.

Thank you.

 
E

Eliyahu Goldin

Moshe,

Please double check. For the items of type ListItemType.Header Text
property should be set to the column name.

Eliyahu

Moshe Pack said:
Eliyahu,

In the ItemCreated event, the Text property for all table cells contains an
empty string.

In the ItemDataBound event, the Text property is indeed filled in for data
cells, but is blank for header cells.

Any other ideas?

Thanks a lot,
Moshe.

Eliyahu Goldin said:
Moshe,

You can try doing this in ItemCreated event. Something like that:

if (e.Item.ItemType != ListItemType.Header)
return;

foreach (TableCell cell in e.Item.Cells)
{
switch (cell.Text)
{
case "Description":
cell.Text = "Another Text";
break;
...
}
}

Eliyahu

Moshe Pack said:
Eliyahu,

If I generate columns automatically (AutoGenerateColumns = True), is there
anything I can do to change the header text other than to create column
aliases in the SQL?

Thanks,
Moshe.

:

Yes Moshe, you can get to header captions from datagrid Columns collection:

myGrid.Columns.HeaderText = "Another Text";

Note that automatically generated columns are not added to the Columns
collection.

Eliyahu

Eliyahu,

Do you have an idea how to do with code-behind?

Thanks,
Moshe.

:

An example:

<asp:BoundColumn DataField="Description" HeaderText="Another
Text"></asp:BoundColumn>

Eliyahu

How can I change header captions when working with a bound DataGrid in
ASP.Net? I am looking for a way to do this without involving
the
SQL.
Thank you.
 
M

Moshe Pack

Eliyahu,

I looped around, writing to the Output window with the following:

For Each cell In e.Item.Cells
If cell.Text <> String.Empty Then
System.Diagnostics.Debug.WriteLine("grdUsers_ItemCreated: '"
& cell.Text.ToString & "'")
End If
Next cell

Nothing gets printed in ItemCreated(). In ItemDataBound() only the data
rows are printed to the Output window. The headers never make it there.

Any ideas?

Thanks,
Moshe


Eliyahu Goldin said:
Moshe,

Please double check. For the items of type ListItemType.Header Text
property should be set to the column name.

Eliyahu

Moshe Pack said:
Eliyahu,

In the ItemCreated event, the Text property for all table cells contains an
empty string.

In the ItemDataBound event, the Text property is indeed filled in for data
cells, but is blank for header cells.

Any other ideas?

Thanks a lot,
Moshe.

Eliyahu Goldin said:
Moshe,

You can try doing this in ItemCreated event. Something like that:

if (e.Item.ItemType != ListItemType.Header)
return;

foreach (TableCell cell in e.Item.Cells)
{
switch (cell.Text)
{
case "Description":
cell.Text = "Another Text";
break;
...
}
}

Eliyahu

Eliyahu,

If I generate columns automatically (AutoGenerateColumns = True), is there
anything I can do to change the header text other than to create column
aliases in the SQL?

Thanks,
Moshe.

:

Yes Moshe, you can get to header captions from datagrid Columns
collection:

myGrid.Columns.HeaderText = "Another Text";

Note that automatically generated columns are not added to the Columns
collection.

Eliyahu

Eliyahu,

Do you have an idea how to do with code-behind?

Thanks,
Moshe.

:

An example:

<asp:BoundColumn DataField="Description" HeaderText="Another
Text"></asp:BoundColumn>

Eliyahu

How can I change header captions when working with a bound
DataGrid in
ASP.Net? I am looking for a way to do this without involving the
SQL.

Thank you.

 
E

Eliyahu Goldin

OK, I've tested it myself. The following ItemCreated event handler WORKS.
B'emet. It adds "aaa" to every header.

private void dg_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.Header)
return;
foreach (TableCell cell in e.Item.Cells)
{
cell.Text += "aaa";
}
}

Eliyahu

Moshe Pack said:
Eliyahu,

I looped around, writing to the Output window with the following:

For Each cell In e.Item.Cells
If cell.Text <> String.Empty Then
System.Diagnostics.Debug.WriteLine("grdUsers_ItemCreated: '"
& cell.Text.ToString & "'")
End If
Next cell

Nothing gets printed in ItemCreated(). In ItemDataBound() only the data
rows are printed to the Output window. The headers never make it there.

Any ideas?

Thanks,
Moshe


Eliyahu Goldin said:
Moshe,

Please double check. For the items of type ListItemType.Header Text
property should be set to the column name.

Eliyahu

Moshe Pack said:
Eliyahu,

In the ItemCreated event, the Text property for all table cells
contains
an
empty string.

In the ItemDataBound event, the Text property is indeed filled in for data
cells, but is blank for header cells.

Any other ideas?

Thanks a lot,
Moshe.

:

Moshe,

You can try doing this in ItemCreated event. Something like that:

if (e.Item.ItemType != ListItemType.Header)
return;

foreach (TableCell cell in e.Item.Cells)
{
switch (cell.Text)
{
case "Description":
cell.Text = "Another Text";
break;
...
}
}

Eliyahu

Eliyahu,

If I generate columns automatically (AutoGenerateColumns = True),
is
there
anything I can do to change the header text other than to create column
aliases in the SQL?

Thanks,
Moshe.

:

Yes Moshe, you can get to header captions from datagrid Columns
collection:

myGrid.Columns.HeaderText = "Another Text";

Note that automatically generated columns are not added to the Columns
collection.

Eliyahu

Eliyahu,

Do you have an idea how to do with code-behind?

Thanks,
Moshe.

:

An example:

<asp:BoundColumn DataField="Description" HeaderText="Another
Text"></asp:BoundColumn>

Eliyahu

How can I change header captions when working with a bound
DataGrid in
ASP.Net? I am looking for a way to do this without
involving
the
SQL.

Thank you.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top