By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,810 Members | 818 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,810 IT Pros & Developers. It's quick & easy.

How can i make GridView Header dynamic?

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.