473,503 Members | 9,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView sort by a column whose header is dynamically created

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 GridView1_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[5].Text =
myDropDownList.SelectedValue;
}
}

In the declaration of this GridView, I have

AllowSorting="true"

and of course I have a Sorting event handler.

Every column is sortable except this column with the dynamic header.
If assign a static value to this header and remove this RowCreated
event handler, this column becomes sortable, too.

So, the question is: How can I make the column with a dynamic header
sortable?
Jun 27 '08 #1
2 5355
It is essentially the same as sorting with a non-dynamically created header,
except you have to control the sort. For a simple sort, you can use a
DataView to bind and set up the sort there. With this form of sort, you can
cache the data, most likely in ViewState, although there are applications
where this is not acceptable.

If you also need paging, you will have to write custom software to do this
and will probably have to retrieve the data each time there is a sort so you
can get a pointer to figure out start and end of the page.

If you want to see how Microsoft does it, you can use Reflector on the .NET
assemblies or, in VS 2008, step into the code. Both can give you a clue of
how MS accomplishes sorting.

Here's a couple of articles:
http://lakshmik.blogspot.com/2006/06...nd-custom.html
http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=428

I am kind of fond of the idea in the second one, although I have not tried
it. Binding with generics would take a bit of work to massage the data
intitially, but the benefits outweigh the extra work.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
"gnewsgroup" <gn********@gmail.comwrote in message
news:67**********************************@m36g2000 hse.googlegroups.com...
>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 GridView1_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[5].Text =
myDropDownList.SelectedValue;
}
}

In the declaration of this GridView, I have

AllowSorting="true"

and of course I have a Sorting event handler.

Every column is sortable except this column with the dynamic header.
If assign a static value to this header and remove this RowCreated
event handler, this column becomes sortable, too.

So, the question is: How can I make the column with a dynamic header
sortable?

Jun 27 '08 #2
On Apr 11, 9:55 am, "Cowboy \(Gregory A. Beamer\)"
<NoSpamMgbwo...@comcast.netNoSpamMwrote:
It is essentially the same as sorting with a non-dynamically createdheader,
except you have to control the sort. For a simple sort, you can use a
DataView to bind and set up the sort there. With this form of sort, you can
cache the data, most likely in ViewState, although there are applications
where this is not acceptable.

If you also need paging, you will have to write custom software to do this
and will probably have to retrieve the data each time there is a sort so you
can get a pointer to figure out start and end of the page.

If you want to see how Microsoft does it, you can use Reflector on the .NET
assemblies or, in VS 2008, step into the code. Both can give you a clue of
how MS accomplishes sorting.

Here's a couple of articles:http://lakshmik.blogspot.com/2006/06...x?quickdoc=428

I am kind of fond of the idea in the second one, although I have not tried
it. Binding with generics would take a bit of work to massage the data
intitially, but the benefits outweigh the extra work.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my bloghttp://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************"
Thank you very much for the references. The problem for me right now
is that the dynamically created header isn't even clickable, unlike
other static header, which you can click and sort.
Jun 27 '08 #3

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

Similar topics

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
9331
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes...
0
1201
by: Smokey Grindle | last post by:
I'm trying desperatly to add a sort order arrow to my grid view and have this code below ofr it... but when the code runs the girdview sortexpression is always = "" never the sort name... why?! i...
1
2831
by: Bill44077 | last post by:
I am dynamically adding a checkbox in a gridview and I find there are several things that I cannot figure out how to address. 1. The width of the checkbox column is very wide. I've tried adding...
4
15352
by: bryan | last post by:
Hi all, I am working on a .net 2.0 web app. On page load I display a gridview with a drop down list (Employees), when the user selects from the drop down list, the grid view is filled with...
4
8312
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the...
4
2528
by: Mark Olbert | last post by:
I'm running into a well-described issue in the ASPNET model that I haven't found a good work around for. I have a GridView to which I dynamically add data-bound TemplateFields at run-time. The...
2
10445
by: =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?= | last post by:
I am building a GridView dynamically adding templatFields according to a Microsoft article. I had to create a class with the ITemplate interface and a method called InstantiateIn. Everything works...
4
10988
by: Craig Buchanan | last post by:
I dynamically add data-bound templates to a gridview in my ascx control. while this works correctly when the gridview is databound to the datatable, i'm having issues on postback. i would like...
0
7095
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
7294
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,...
0
7361
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7015
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
7470
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...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
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
3183
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.