all groups > asp.net datagrid control > november 2004 >
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.
Eliyahu, Do you have an idea how to do with code-behind? Thanks, Moshe. [quoted text, click to view] "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. > >
An example: <asp:BoundColumn DataField="Description" HeaderText="Another Text"></asp:BoundColumn> Eliyahu [quoted text, click to view] "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.
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 [quoted text, click to view] "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, 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. [quoted text, click to view] "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, 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. [quoted text, click to view] "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, 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 [quoted text, click to view] "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, 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 [quoted text, click to view] "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, Please double check. For the items of type ListItemType.Header Text property should be set to the column name. Eliyahu [quoted text, click to view] "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. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
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 [quoted text, click to view] "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_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" 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. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
Don't see what you're looking for? Try a search.
|
|
|