473,756 Members | 8,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview Sorting does not work after dynamically changing the Header text

Hi Everyone:

I have a gridview control with AllowSorting="T rue" and work ok.
But my page will be used by different user from different region so i
need to change the HeaderText based on language like english or french
etc.When i updat ethe header on GridView1_RowCr eated sorting does not
work anymore. Below are my code. Is this because of BoundField. Can
someone please help me with this issue. Thanks in advance.

<asp:GridView ID="GridView1" AutoGenerateCol umns="false"
runat="server" AllowSorting="T rue"
DataSourceID="O bjectDataSource 1"
OnRowCreated="G ridView1_RowCre ated">
<Columns>
<asp:BoundFie ld HtmlEncode="Fal se" HeaderStyle-
VerticalAlign=" Top" DataFormatStrin g="{0:C4}"
DataField="GRAN T_PRICE" HeaderText="GRA NT
PRICE" HeaderStyle-ForeColor="whit e" SortExpression= "GRANT_PRIC E"
ItemStyle-HorizontalAlign ="right" />
<asp:BoundFie ld DataField="GRAN T_DATE"
HeaderText="GRA NT DATE" HeaderStyle-HorizontalAlign ="Right"
HeaderStyle-ForeColor="whit e"
HeaderStyle-VerticalAlign=" Top" ItemStyle-
Wrap="false" SortExpression= "GRANT_DATE "
ItemStyle-HorizontalAlign ="right" />
<asp:BoundFie ld DataField="PLAN _ID"
HeaderText="PLA N_ID" HeaderStyle-VerticalAlign=" Top" HeaderStyle-
ForeColor="whit e"
SortExpression= "PLAN_ID" />
<asp:BoundFie ld DataField="AGGR EMENT"
HeaderText="AGG REMENT Received" HeaderStyle-VerticalAlign=" Top"
HeaderStyle-ForeColor="whit e"
SortExpression= "AGGREMENT" />
<asp:BoundFie ld DataField="BALA NCE_OPTIONS"
HeaderText="BAL ANCE OPTIONS" HeaderStyle-VerticalAlign=" Top"
HeaderStyle-ForeColor="whit e"
SortExpression= "BALANCE_OPTION S" ItemStyle-
HorizontalAlign ="right" / </Columns>
</asp:GridView>

<asp:ObjectData Source ID="ObjectDataS ource1"
runat="server" SelectMethod="G etDetail"
TypeName="cBMOS OP">
<SelectParamete rs>
<asp:Paramete r DefaultValue="9 999" Name="clientID"
Type="String" />
<asp:Paramete r DefaultValue="1 234567"
Name="baseID" Type="String" />
</SelectParameter s>
</asp:ObjectDataS ource>

protected void GridView1_RowCr eated( object sender,
GridViewRowEven tArgs e )
{
if ( e.Row.RowType == DataControlRowT ype.Header )
{
e.Row.Cells[0].Text = "GrantPrice 1";
e.Row.Cells[0].HorizontalAlig n = HorizontalAlign .Left;
e.Row.Cells[1].Text = "GrantDate1 ";
e.Row.Cells[1].HorizontalAlig n = HorizontalAlign .Left;
e.Row.Cells[2].Text = "PlanID1";
e.Row.Cells[2].HorizontalAlig n = HorizontalAlign .Left;
e.Row.Cells[3].Text = "AggrementRecei ved1";
e.Row.Cells[3].HorizontalAlig n = HorizontalAlign .Left;
e.Row.Cells[4].Text = "AvailableShare s1";
e.Row.Cells[4].HorizontalAlig n = HorizontalAlign .Right;
}
}

Apr 24 '07 #1
0 1936

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

Similar topics

12
2391
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that field... This grid displayes results based on users search.. public static int numberDiv; private void Page_Load(object sender, System.EventArgs e) {
5
4837
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens automatically if the data doesn't change. But if records have been added or deleted then it looks as if some code is necessary: I've done this by using GridView.SelectedValue to get the key value of the currently selected Row and then by itterating...
1
7012
by: tfsmag | last post by:
Hello, I have a function that returns a dynamically created gridview. This works fine, however it does not seem to be able to maintain state when adding sorting or paging to the gridview. Does anyone have any idea how to get this to work? below is the code. Please bear in mind that the function is actually located in a seperate class file from the page that actually returns the grid. ---code for function that returns the grid, this is...
5
3376
by: yefei | last post by:
In my web design, I display records from a SQL DataBase according to some filters the GridView is defined with select commands and selest parameters however, I also want to display all records in the database when the user press a "View All" button. In this case, I need to change the select comand and clear the parameters. And I did this in the button_click() event. the GridView can display desired results when I press the "View All"...
1
541
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this OleDbParameterCollection" whenI try to write a new record. Delete and Modify work fine its just the add record function causes the error.
1
10407
by: Evan M. | last post by:
Here's my GridView and my SqlDataSource <asp:GridView ID="ContactHistoryGrid" runat="server" AutoGenerateColumns="False" DataSourceID="ContactHistoryDS" DataKeyNames="JobHistoryID" OnRowCreated="ContactHistoryGrid_RowCreated" CssClass="GridViewTable" GridLines="None" CellSpacing="1" CellPadding="3" AllowSorting="True" AllowPaging="True"> <EmptyDataTemplate>
0
1412
by: pargat.singh | last post by:
Hi: I am using a grid and having a problem with sorting. Below are my code and change the header name at run time as below based on language.If i don't change the header name it work. Can someone please help me so that i can enable the sorting and change the header as well. Thanks, in advance. <asp:GridView ID="GridView1" CellPadding="5"
2
5404
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 GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) {
3
14005
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 Header Data it is displayed as a link that raises a Sorting Event upon postback. In my InstantiateIn method I create a LinkButton for my Header. I have added a handler to the LinkButton that calls a method upon DataBinding. In that method I have...
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10040
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9873
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8713
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.