How to change header captions

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default How to change header captions

    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.
    Moshe Pack Guest

  2. Similar Questions and Discussions

    1. #38602 [Asn->Csd]: header( "HTTP/1.0 ..." ) does not change proto ver. Fix included.
      ID: 38602 Updated by: iliaa@php.net Reported By: tomsn at inetoffice dot com -Status: Assigned +Status: ...
    2. #38602 [Opn->Asn]: header( "HTTP/1.0 ..." ) does not change proto ver. Fix included.
      ID: 38602 Updated by: tony2001@php.net Reported By: tomsn at inetoffice dot com -Status: Open +Status: ...
    3. How do you change the vertical grid line color of the header in a datagrid???
      Hi, I managed to change the vertical grid line color for all the rows, but can't get it to work for the header as well. Any help? Thanks
    4. IPTC Captions
      I need to manipulate the IPTC captions within a jpeg using Perl. Is their a module or an easy way of doing this in Perl ? Thanks Neill
    5. Help - Photo Captions
      David, I couldn't edit for some reason. The next-to-last step in 2 should have said put 10 percent in the Height box. (Have to remember not to...
  3. #2

    Default Re: How to change header captions

    An example:

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

    Eliyahu

    "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    news:5F498ADB-694B-41E3-8B4A-4F58BBA8FAFA@microsoft.com...
    > 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.

    Eliyahu Goldin Guest

  4. #3

    Default Re: How to change header captions

    Eliyahu,

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

    Thanks,
    Moshe.

    "Eliyahu Goldin" wrote:
    > An example:
    >
    > <asp:BoundColumn DataField="Description" HeaderText="Another
    > Text"></asp:BoundColumn>
    >
    > Eliyahu
    >
    > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    > news:5F498ADB-694B-41E3-8B4A-4F58BBA8FAFA@microsoft.com...
    > > 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.
    >
    >
    >
    Moshe Pack Guest

  5. #4

    Default Re: How to change header captions

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

    myGrid.Columns[i].HeaderText = "Another Text";

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

    Eliyahu

    "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    news:8F2D43AD-9CA5-4D93-8D6F-03728DBF1FCA@microsoft.com...
    > Eliyahu,
    >
    > Do you have an idea how to do with code-behind?
    >
    > Thanks,
    > Moshe.
    >
    > "Eliyahu Goldin" wrote:
    >
    > > An example:
    > >
    > > <asp:BoundColumn DataField="Description" HeaderText="Another
    > > Text"></asp:BoundColumn>
    > >
    > > Eliyahu
    > >
    > > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    > > news:5F498ADB-694B-41E3-8B4A-4F58BBA8FAFA@microsoft.com...
    > > > 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.
    > >
    > >
    > >

    Eliyahu Goldin Guest

  6. #5

    Default Re: How to change header captions

    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" wrote:
    > Yes Moshe, you can get to header captions from datagrid Columns collection:
    >
    > myGrid.Columns[i].HeaderText = "Another Text";
    >
    > Note that automatically generated columns are not added to the Columns
    > collection.
    >
    > Eliyahu
    >
    > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    > news:8F2D43AD-9CA5-4D93-8D6F-03728DBF1FCA@microsoft.com...
    > > Eliyahu,
    > >
    > > Do you have an idea how to do with code-behind?
    > >
    > > Thanks,
    > > Moshe.
    > >
    > > "Eliyahu Goldin" wrote:
    > >
    > > > An example:
    > > >
    > > > <asp:BoundColumn DataField="Description" HeaderText="Another
    > > > Text"></asp:BoundColumn>
    > > >
    > > > Eliyahu
    > > >
    > > > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    > > > news:5F498ADB-694B-41E3-8B4A-4F58BBA8FAFA@microsoft.com...
    > > > > 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.
    > > >
    > > >
    > > >
    >
    >
    >
    Moshe Pack Guest

  7. #6

    Default Re: How to change header captions

    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" <MoshePack@discussions.microsoft.com> wrote in message
    news:F7D5C93D-473C-4E64-B0C1-BBF154BA1A07@microsoft.com...
    > 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" wrote:
    >
    > > Yes Moshe, you can get to header captions from datagrid Columns
    collection:
    > >
    > > myGrid.Columns[i].HeaderText = "Another Text";
    > >
    > > Note that automatically generated columns are not added to the Columns
    > > collection.
    > >
    > > Eliyahu
    > >
    > > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    > > news:8F2D43AD-9CA5-4D93-8D6F-03728DBF1FCA@microsoft.com...
    > > > Eliyahu,
    > > >
    > > > Do you have an idea how to do with code-behind?
    > > >
    > > > Thanks,
    > > > Moshe.
    > > >
    > > > "Eliyahu Goldin" wrote:
    > > >
    > > > > An example:
    > > > >
    > > > > <asp:BoundColumn DataField="Description" HeaderText="Another
    > > > > Text"></asp:BoundColumn>
    > > > >
    > > > > Eliyahu
    > > > >
    > > > > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    > > > > news:5F498ADB-694B-41E3-8B4A-4F58BBA8FAFA@microsoft.com...
    > > > > > 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.
    > > > >
    > > > >
    > > > >
    > >
    > >
    > >

    Eliyahu Goldin Guest

  8. #7

    Default Re: How to change header captions

    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" wrote:
    > 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" <MoshePack@discussions.microsoft.com> wrote in message
    > news:F7D5C93D-473C-4E64-B0C1-BBF154BA1A07@microsoft.com...
    > > 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" wrote:
    > >
    > > > Yes Moshe, you can get to header captions from datagrid Columns
    > collection:
    > > >
    > > > myGrid.Columns[i].HeaderText = "Another Text";
    > > >
    > > > Note that automatically generated columns are not added to the Columns
    > > > collection.
    > > >
    > > > Eliyahu
    > > >
    > > > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    > > > news:8F2D43AD-9CA5-4D93-8D6F-03728DBF1FCA@microsoft.com...
    > > > > Eliyahu,
    > > > >
    > > > > Do you have an idea how to do with code-behind?
    > > > >
    > > > > Thanks,
    > > > > Moshe.
    > > > >
    > > > > "Eliyahu Goldin" wrote:
    > > > >
    > > > > > An example:
    > > > > >
    > > > > > <asp:BoundColumn DataField="Description" HeaderText="Another
    > > > > > Text"></asp:BoundColumn>
    > > > > >
    > > > > > Eliyahu
    > > > > >
    > > > > > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    > > > > > news:5F498ADB-694B-41E3-8B4A-4F58BBA8FAFA@microsoft.com...
    > > > > > > 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.
    > > > > >
    > > > > >
    > > > > >
    > > >
    > > >
    > > >
    >
    >
    >
    Moshe Pack Guest

  9. #8

    Default Re: How to change header captions

    Moshe,

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

    Eliyahu

    "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    news:93917981-DF44-4F6E-8678-320DB7455BCF@microsoft.com...
    > 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" wrote:
    >
    > > 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" <MoshePack@discussions.microsoft.com> wrote in message
    > > news:F7D5C93D-473C-4E64-B0C1-BBF154BA1A07@microsoft.com...
    > > > 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" wrote:
    > > >
    > > > > Yes Moshe, you can get to header captions from datagrid Columns
    > > collection:
    > > > >
    > > > > myGrid.Columns[i].HeaderText = "Another Text";
    > > > >
    > > > > Note that automatically generated columns are not added to the
    Columns
    > > > > collection.
    > > > >
    > > > > Eliyahu
    > > > >
    > > > > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    > > > > news:8F2D43AD-9CA5-4D93-8D6F-03728DBF1FCA@microsoft.com...
    > > > > > Eliyahu,
    > > > > >
    > > > > > Do you have an idea how to do with code-behind?
    > > > > >
    > > > > > Thanks,
    > > > > > Moshe.
    > > > > >
    > > > > > "Eliyahu Goldin" wrote:
    > > > > >
    > > > > > > An example:
    > > > > > >
    > > > > > > <asp:BoundColumn DataField="Description" HeaderText="Another
    > > > > > > Text"></asp:BoundColumn>
    > > > > > >
    > > > > > > Eliyahu
    > > > > > >
    > > > > > > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in
    message
    > > > > > > news:5F498ADB-694B-41E3-8B4A-4F58BBA8FAFA@microsoft.com...
    > > > > > > > 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.
    > > > > > >
    > > > > > >
    > > > > > >
    > > > >
    > > > >
    > > > >
    > >
    > >
    > >

    Eliyahu Goldin Guest

  10. #9

    Default Re: How to change header captions

    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_ItemC reated: '"
    & 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" wrote:
    > Moshe,
    >
    > Please double check. For the items of type ListItemType.Header Text
    > property should be set to the column name.
    >
    > Eliyahu
    >
    > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    > news:93917981-DF44-4F6E-8678-320DB7455BCF@microsoft.com...
    > > 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" wrote:
    > >
    > > > 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" <MoshePack@discussions.microsoft.com> wrote in message
    > > > news:F7D5C93D-473C-4E64-B0C1-BBF154BA1A07@microsoft.com...
    > > > > 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" wrote:
    > > > >
    > > > > > Yes Moshe, you can get to header captions from datagrid Columns
    > > > collection:
    > > > > >
    > > > > > myGrid.Columns[i].HeaderText = "Another Text";
    > > > > >
    > > > > > Note that automatically generated columns are not added to the
    > Columns
    > > > > > collection.
    > > > > >
    > > > > > Eliyahu
    > > > > >
    > > > > > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    > > > > > news:8F2D43AD-9CA5-4D93-8D6F-03728DBF1FCA@microsoft.com...
    > > > > > > Eliyahu,
    > > > > > >
    > > > > > > Do you have an idea how to do with code-behind?
    > > > > > >
    > > > > > > Thanks,
    > > > > > > Moshe.
    > > > > > >
    > > > > > > "Eliyahu Goldin" wrote:
    > > > > > >
    > > > > > > > An example:
    > > > > > > >
    > > > > > > > <asp:BoundColumn DataField="Description" HeaderText="Another
    > > > > > > > Text"></asp:BoundColumn>
    > > > > > > >
    > > > > > > > Eliyahu
    > > > > > > >
    > > > > > > > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in
    > message
    > > > > > > > news:5F498ADB-694B-41E3-8B4A-4F58BBA8FAFA@microsoft.com...
    > > > > > > > > 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.
    > > > > > > >
    > > > > > > >
    > > > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > >
    > > >
    > > >
    >
    >
    >
    Moshe Pack Guest

  11. #10

    Default Re: How to change header captions

    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" <MoshePack@discussions.microsoft.com> wrote in message
    news:03134717-419D-4F18-8A14-8659981AC5C4@microsoft.com...
    > 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_ItemC reated:
    '"
    > & 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" wrote:
    >
    > > Moshe,
    > >
    > > Please double check. For the items of type ListItemType.Header Text
    > > property should be set to the column name.
    > >
    > > Eliyahu
    > >
    > > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in message
    > > news:93917981-DF44-4F6E-8678-320DB7455BCF@microsoft.com...
    > > > 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" wrote:
    > > >
    > > > > 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" <MoshePack@discussions.microsoft.com> wrote in message
    > > > > news:F7D5C93D-473C-4E64-B0C1-BBF154BA1A07@microsoft.com...
    > > > > > 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" wrote:
    > > > > >
    > > > > > > Yes Moshe, you can get to header captions from datagrid Columns
    > > > > collection:
    > > > > > >
    > > > > > > myGrid.Columns[i].HeaderText = "Another Text";
    > > > > > >
    > > > > > > Note that automatically generated columns are not added to the
    > > Columns
    > > > > > > collection.
    > > > > > >
    > > > > > > Eliyahu
    > > > > > >
    > > > > > > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in
    message
    > > > > > > news:8F2D43AD-9CA5-4D93-8D6F-03728DBF1FCA@microsoft.com...
    > > > > > > > Eliyahu,
    > > > > > > >
    > > > > > > > Do you have an idea how to do with code-behind?
    > > > > > > >
    > > > > > > > Thanks,
    > > > > > > > Moshe.
    > > > > > > >
    > > > > > > > "Eliyahu Goldin" wrote:
    > > > > > > >
    > > > > > > > > An example:
    > > > > > > > >
    > > > > > > > > <asp:BoundColumn DataField="Description" HeaderText="Another
    > > > > > > > > Text"></asp:BoundColumn>
    > > > > > > > >
    > > > > > > > > Eliyahu
    > > > > > > > >
    > > > > > > > > "Moshe Pack" <MoshePack@discussions.microsoft.com> wrote in
    > > message
    > > > > > > > > news:5F498ADB-694B-41E3-8B4A-4F58BBA8FAFA@microsoft.com...
    > > > > > > > > > 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.
    > > > > > > > >
    > > > > > > > >
    > > > > > > > >
    > > > > > >
    > > > > > >
    > > > > > >
    > > > >
    > > > >
    > > > >
    > >
    > >
    > >

    Eliyahu Goldin Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139