473,479 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

.Net 2.0 C# GridView question

Hi,

Would someone tell me how to manipulate the Header of a GridView?
My DataSet is like this:

_id _name
1 John
2 Mary

But I want the GridView in my webform to show up like this:

ID Name
1 John
2 Mary

Thanks for help.
Jason
May 16 '07 #1
3 8771
Jason,

You can change the header text of the GridView column by:

GridView1.Columns[0].HeaderText = "ID";

Regards,
Prashanth.
On May 16, 1:28 pm, "Jason Huang" <JasonHuang8...@hotmail.comwrote:
Hi,

Would someone tell me how to manipulate the Header of a GridView?
My DataSet is like this:

_id _name
1 John
2 Mary

But I want the GridView in my webform to show up like this:

ID Name
1 John
2 Mary

Thanks for help.

Jason

May 16 '07 #2
Another way is to define the column your self that way you know for shaw the
heading corresponds to the correct data see below:

//disable auto column generation
MyGridView.AutoGenerateColumns = false;

//define id column
BoundField field = new BoundField();
field.DataField = "Id";
field.HeaderText = "TestId";
MyGridView.Columns.Add(field);

//define Name column
field.DataField = "Name";
field.HeaderText = "TestName";
MyGridView.Columns.Add(field);

MyGridView.DataSource = _myDataSource;
MyGridView.DataBind();

"Prashanth Rao" wrote:
Jason,

You can change the header text of the GridView column by:

GridView1.Columns[0].HeaderText = "ID";

Regards,
Prashanth.
On May 16, 1:28 pm, "Jason Huang" <JasonHuang8...@hotmail.comwrote:
Hi,

Would someone tell me how to manipulate the Header of a GridView?
My DataSet is like this:

_id _name
1 John
2 Mary

But I want the GridView in my webform to show up like this:

ID Name
1 John
2 Mary

Thanks for help.

Jason


May 16 '07 #3

One more way is to set it in the Design time like this:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="First Name"
SortExpression="FirstName">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("Id") %>' Width="108px"></asp:Label>
</ItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%#
Bind("Name") %>' Width="108px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</gridview>
May 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5652
by: theKirk | last post by:
using Visual Studio 2005 C# ASP.NET I know there has to be a simple way to do this....I want to use C# in a code behind for aspx. Populate a GridView from an xml file Add Fields to the...
6
3018
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
4
2604
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I...
7
14784
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
1
3220
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an...
4
1800
by: Chris | last post by:
Hi, I read about client callback and i have a question. Assume the option "sorting" is set in a gridview. Each time the user clicks on a fieldname, the data are sorted. My question is: are...
3
311
by: Gonza | last post by:
Hi group, i have a question relatred to gridview and postback (i should probably know this by now, considering i've been working with .net for a few years now, but baahh). Why could a gridview...
1
8536
by: Barry L. Camp | last post by:
Hi all, Wondering if someone can help with a nagging problem I am having using a GridView and an ObjectDataSource. I have a simple situation where I am trying to delete a row from a table, but...
4
11114
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have a vb.net 2.0 app that is loading a GridView with a DataSource that is returned from a function. The definitions in the function are: Dim ReportDS As DataSet = New DataSet Dim...
1
1612
by: Cirene | last post by:
This is confusing... I have a gridview (gv1) with another gridview (gv2) inside of it. gv1 has a bunch of house listings and within each row is a group of related house pictures (gv2). I'm...
0
7027
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6899
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7019
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6719
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6847
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4757
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4463
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2970
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.