473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How can i make GridView Header dynamic?

I would like to make my Gridview header dynmic i.e databinded from
database..
I want my users to be able to change the headers on the fly..
Any ideas?

Nov 21 '07 #1
7 12929
On Nov 21, 11:44 am, "rote" <naijaco...@hotmail.comwrote:
I would like to make my Gridview header dynmic i.e databinded from
database..
I want my users to be able to change the headers on the fly..
Any ideas?
Hi,
We had a similar kind of requirement. We created a new header
above the GridView header. For that, we added new GirdViewRow with
proper cells (columns) and data, and it worked. You may use the same.
I dont know whether it solves your complete problem, but you will need
to create new GridViewRow for adding some header above the GridView's
default header.

Thanks,
coolCoder
Nov 21 '07 #2
"rote" <na********@hotmail.comwrote in message
news:eL**************@TK2MSFTNGP02.phx.gbl...
>I would like to make my Gridview header dynamic i.e databound from
database..
I want my users to be able to change the headers on the fly..
Can you clarify what you mean, please...

Are you saying that you want your users to be able to choose which columns
are displayed, or just to be able to change the text displayed at the top of
each column...?

If the latter, what happens if e.g. your GridView has four columns and they
specify the same header for all of them...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 21 '07 #3
Mark thanks for the reply.
The header colmuns would be fixed so lets say 4 and thats it.
Just to be able to change the text displayed on top of each column.

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ul**************@TK2MSFTNGP05.phx.gbl...
"rote" <na********@hotmail.comwrote in message
news:eL**************@TK2MSFTNGP02.phx.gbl...
>>I would like to make my Gridview header dynamic i.e databound from
database..
I want my users to be able to change the headers on the fly..

Can you clarify what you mean, please...

Are you saying that you want your users to be able to choose which columns
are displayed, or just to be able to change the text displayed at the top
of each column...?

If the latter, what happens if e.g. your GridView has four columns and
they specify the same header for all of them...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 22 '07 #4
"rote" <na********@hotmail.comwrote in message
news:OC**************@TK2MSFTNGP02.phx.gbl...
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ul**************@TK2MSFTNGP05.phx.gbl...
>"rote" <na********@hotmail.comwrote in message
news:eL**************@TK2MSFTNGP02.phx.gbl...
>>>I would like to make my Gridview header dynamic i.e databound from
database..
I want my users to be able to change the headers on the fly..

Can you clarify what you mean, please...

Are you saying that you want your users to be able to choose which
columns are displayed, or just to be able to change the text displayed at
the top of each column...?

If the latter, what happens if e.g. your GridView has four columns and
they specify the same header for all of them...?

The header colmuns would be fixed so lets say 4 and thats it.
Just to be able to change the text displayed on top of each column.
<asp:GridView ID="MyGridView" runat="server"
OnRowDataBound="MyGridView_RowDataBound" AutoGenerateColumns="False">

protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = "First";
e.Row.Cells[1].Text = "Second";
e.Row.Cells[2].Text = "Third";
e.Row.Cells[3].Text = "Fourth";
}
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 22 '07 #5
Thanks CoolCoder for the reply.
But can you explain how you added the GridViewRow and placed it at the
header.Some snippet code,resource etc
My GridView is using a TemplateField
<asp:TemplateField HeaderText="Year">
<ItemTemplate/>
</asp:TemplateField>
I tried databinding the data on the HeaderText above but doesn't like it...

"coolCoder" <an*********************@gmail.comwrote in message
news:7e**********************************@c29g2000 hsa.googlegroups.com...
On Nov 21, 11:44 am, "rote" <naijaco...@hotmail.comwrote:
>I would like to make my Gridview header dynmic i.e databinded from
database..
I want my users to be able to change the headers on the fly..
Any ideas?

Hi,
We had a similar kind of requirement. We created a new header
above the GridView header. For that, we added new GirdViewRow with
proper cells (columns) and data, and it worked. You may use the same.
I dont know whether it solves your complete problem, but you will need
to create new GridViewRow for adding some header above the GridView's
default header.

Thanks,
coolCoder

Nov 22 '07 #6
hmm.. thanks Mark
I have already started creating a GridViewRow under the same event.
But your snippet looks like less code and i can just loop through e.Rows and
insert my values
Let me see how it goes...

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:OV**************@TK2MSFTNGP06.phx.gbl...
"rote" <na********@hotmail.comwrote in message
news:OC**************@TK2MSFTNGP02.phx.gbl...
>"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ul**************@TK2MSFTNGP05.phx.gbl...
>>"rote" <na********@hotmail.comwrote in message
news:eL**************@TK2MSFTNGP02.phx.gbl...

I would like to make my Gridview header dynamic i.e databound from
database..
I want my users to be able to change the headers on the fly..

Can you clarify what you mean, please...

Are you saying that you want your users to be able to choose which
columns are displayed, or just to be able to change the text displayed
at the top of each column...?

If the latter, what happens if e.g. your GridView has four columns and
they specify the same header for all of them...?

The header colmuns would be fixed so lets say 4 and thats it.
Just to be able to change the text displayed on top of each column.

<asp:GridView ID="MyGridView" runat="server"
OnRowDataBound="MyGridView_RowDataBound" AutoGenerateColumns="False">

protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = "First";
e.Row.Cells[1].Text = "Second";
e.Row.Cells[2].Text = "Third";
e.Row.Cells[3].Text = "Fourth";
}
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 22 '07 #7
"rote" <na********@hotmail.comwrote in message
news:uv**************@TK2MSFTNGP02.phx.gbl...
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:OV**************@TK2MSFTNGP06.phx.gbl...
>"rote" <na********@hotmail.comwrote in message
news:OC**************@TK2MSFTNGP02.phx.gbl...
>>"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ul**************@TK2MSFTNGP05.phx.gbl...
"rote" <na********@hotmail.comwrote in message
news:eL**************@TK2MSFTNGP02.phx.gbl...

>I would like to make my Gridview header dynamic i.e databound from
>database..
I want my users to be able to change the headers on the fly..

Can you clarify what you mean, please...

Are you saying that you want your users to be able to choose which
columns are displayed, or just to be able to change the text displayed
at the top of each column...?

If the latter, what happens if e.g. your GridView has four columns and
they specify the same header for all of them...?

The header colmuns would be fixed so lets say 4 and thats it.
Just to be able to change the text displayed on top of each column.

<asp:GridView ID="MyGridView" runat="server"
OnRowDataBound="MyGridView_RowDataBound" AutoGenerateColumns="False">

protected void MyGridView_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = "First";
e.Row.Cells[1].Text = "Second";
e.Row.Cells[2].Text = "Third";
e.Row.Cells[3].Text = "Fourth";
}
}

I have already started creating a GridViewRow under the same event.
But your snippet looks like less code and i can just loop through e.Rows
and insert my values
Let me see how it goes...
If you just want to change the text in the existing header row, there's no
need to create a new row...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 22 '07 #8

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

Similar topics

0
by: Mark Parter | last post by:
I'm adding a dynamic column to a gridview control at runtime but I'm encountering a problem whereby I can only add 1 item to the column header. The column header should show the date in the...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
1
by: John_H | last post by:
Re: ASP.NET 2.0 I would like suggestions or code examples on how to collect a variable length list of input data (item# & item quantity specifically). I thought that I could accomplish this...
1
by: ShiroiRyuu | last post by:
tenho um dataset que tem um numero de colunas variavel que é apresentado num grid view e eu queria podsr agrupar alguns headers desse gridview quando as colunas possuirem o mesmo nome. por exemplo...
0
by: palgre | last post by:
HI All, I want to disply dynamic Columns and Dynamic Header to that column in a GRID VIEW. The application is kind of TimeSheet for entering weekly hrs for a month. 1. First of all I want to...
1
by: DJE | last post by:
Is it possible to make the header of a gridview contain data from the grid? I have nested gridviews and in the Child gridview I want the column heading to be "Email To Tom" for Parent Row1, "Email...
9
by: lilOlMe | last post by:
Hi there! I have generated a GridView that looks something like: SportName| CompanyNameX |CompanyNameY |CompanyNameZ Hockey.....| Shipping------------ |Accounting-------- |Shipping------------...
2
by: gnewsgroup | last post by:
I have a GridView, in which the header of one column changes depending on the selected value of a DropDownList outside of this GridView. I did this dynamic header through protected void...
3
Frinavale
by: Frinavale | last post by:
I have implemented the ITemplate interface to dynamically "display" complicated data in a GridView. For the life of me I cannot implement the template in such a way that when it is applied to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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,...

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.