Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 5th, 2006, 06:18 AM
Authorized User
 
Join Date: Apr 2006
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sorting GridView manually

Hi,
I run a bi-lingual site and so, I need to set the text values of the headings via code-behind in PageLoad:
If lang = "en" Then
EvenemangGridView.HeaderRow.Cells(0).Text = "Date"
EvenemangGridView.HeaderRow.Cells(1).Text = "Time"
etc.

It works fine, but I noticed that the sorting functionality was broken after setting the text dynamically. This is what I have in the aspx page:
<asp:GridView ID="EvenemangGridView" runat="server" AutoGenerateColumns="False" DataSourceID="EvenemangDataSource"
                EmptyDataText="" Style="z-index: 100; left: 0px; position: relative;" AllowPaging="True"
                CellPadding="0" ForeColor="#333333" GridLines="None" HorizontalAlign="Left" PageSize="10"
                Width="590px" AllowSorting="True" EnableViewState="false">
                <Columns>
                    <asp:BoundField DataField="datum" HeaderText="datum" SortExpression="datum">
                        <ItemStyle Width="86px" />
                    </asp:BoundField>
etc.

I've searched the net for a solution but to no avail. Please help me out if you can!

Many thanks in advance!
Pettrer

Coding is indeed a nine-to-five job; nine pm to five am.
__________________
Coding is indeed a nine-to-five job; nine pm to five am.
 
Old June 5th, 2006, 10:20 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi pettrer,

By setting the text property of the cell, you effectively clear out the entire cell, including stuff used for sorting.

Instead, you should set the HeaderText property of each column. That sets the text, while it preserves stuff like the SortExpression.

Something like this should work:

EvenemangGridView.Columns(0).HeaderText = "Date"
EvenemangGridView.Columns(0).HeaderText = "Time"

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old June 5th, 2006, 10:40 AM
Authorized User
 
Join Date: Apr 2006
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So simple, yet so beautiful! :-)

Once agin, you've come to my rescue. Thanks Imar!

P

Coding is indeed a nine-to-five job; nine pm to five am.
 
Old June 5th, 2006, 10:51 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome.

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004





Similar Threads
Thread Thread Starter Forum Replies Last Post
[Resolved] GridView - manually set SortExpression snufse ASP.NET 2.0 Basics 1 November 3rd, 2008 10:00 AM
GridView Sorting Aker C# 7 May 29th, 2008 07:50 AM
SORTING IN GRIDVIEW santosh.kundlik ASP.NET 2.0 Professional 0 March 22nd, 2007 03:52 AM
Sorting GridView DARSIN ASP.NET 2.0 Basics 0 December 14th, 2004 09:36 AM
Re:Sorting gridview m_rajib .NET Framework 2.0 2 December 14th, 2004 08:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.