469,648 Members | 1,618 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,648 developers. It's quick & easy.

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 5150
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Smokey Grindle | last post: by
1 post views Thread by Bill44077 | last post: by
4 posts views Thread by Ken Wigle | last post: by
4 posts views Thread by Mark Olbert | last post: by
2 posts views Thread by =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?= | last post: by
4 posts views Thread by Craig Buchanan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.