473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

DataView.sort does not work thru LinkButton

Hi,

I have been working on Sorting within a Datagrid that is created
programmatically, so everything is created in the code-behind.

I have a Template Column that consists of a Header Template. The
Header Template consists of LinkButtons, so when triggered it will fire
an event calling the following function:

e.CommandName - contains "Sort1", "Sort2", etc.

protected void Epot_Command(object sender, CommandEventArgs e)

{
Response.Write("link button clicked");
int buttonClicked = Convert.ToInt32(e.CommandName.Remove(0,4));
this.sortString = "Col" + buttonClicked.ToString();

// sort data
DataView dataView = this.dt.DefaultView;
dataView.Sort = sortString + " DESC";
this.EpotDG.DataSource = dataView;
this.EpotDG.DataBind();
}

So to sort my data, I have a dataView which I obtained from the
DataTable. The variable "sortString" contains the Column names,
such as Col1, Col2 - this is obtained from the xml file.

<Col1>Benefits</Col1>
<Col2>Benefit Areas</Col2>

Everything is working, however the dataRows are not being sorted.
Please advise how to proceed.
Many thanks..
nish

Nov 19 '05 #1
3 3436
In the InitializeComponent() function of the designer generated code, do you
have code that adds the event handler. It should look something like ...

this.linkButton1.Click += new System.EventHandler(this.Epot_Command);

--
Gopal Rangaswamy
Microsoft Certified Solutions Developer
FMS, Inc.
<http://www.fmsinc.com/consulting>
<http://www.fmsinc.com/dotnet/SourceBook/>

"nish" <ni********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi,

I have been working on Sorting within a Datagrid that is created
programmatically, so everything is created in the code-behind.

I have a Template Column that consists of a Header Template. The
Header Template consists of LinkButtons, so when triggered it will fire
an event calling the following function:

e.CommandName - contains "Sort1", "Sort2", etc.

protected void Epot_Command(object sender, CommandEventArgs e)

{
Response.Write("link button clicked");
int buttonClicked = Convert.ToInt32(e.CommandName.Remove(0,4));
this.sortString = "Col" + buttonClicked.ToString();

// sort data
DataView dataView = this.dt.DefaultView;
dataView.Sort = sortString + " DESC";
this.EpotDG.DataSource = dataView;
this.EpotDG.DataBind();
}

So to sort my data, I have a dataView which I obtained from the
DataTable. The variable "sortString" contains the Column names,
such as Col1, Col2 - this is obtained from the xml file.

<Col1>Benefits</Col1>
<Col2>Benefit Areas</Col2>

Everything is working, however the dataRows are not being sorted.
Please advise how to proceed.
Many thanks..
nish

Nov 19 '05 #2
Hi Gopal,

I have the following statement in my DataGrid_ItemCreated function...

lnkHeader[i].CommandName = "Sort" + i;
lnkHeader[i].CommandArgument = "Descending";
lnkHeader[i].Command += new CommandEventHandler(Epot_Command);

this way the LinkButton handler is triggered and I know what value is
being clicked for sorting.

Should I try adding the linkButton1.Click in the Init function?
Thanks for your help.

Regards,
Nisha
Thanks for your help.

Nov 19 '05 #3
Hi Nisha,
I suspect that you are not able to step into the event handle because the
ItemCreated event is raised everytime a control is created, both during
round-trips and at the time data is bound to the control. Try to find a
different place to add this code like the Init function.
Hope this helps you.

--
Gopal Rangaswamy
Microsoft Certified Solutions Developer
FMS, Inc.
<http://www.fmsinc.com/consulting>
<http://www.fmsinc.com/dotnet/SourceBook/>
"nish" <ni********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi Gopal,

I have the following statement in my DataGrid_ItemCreated function...

lnkHeader[i].CommandName = "Sort" + i;
lnkHeader[i].CommandArgument = "Descending";
lnkHeader[i].Command += new CommandEventHandler(Epot_Command);

this way the LinkButton handler is triggered and I know what value is
being clicked for sorting.

Should I try adding the linkButton1.Click in the Init function?
Thanks for your help.

Regards,
Nisha
Thanks for your help.

Nov 19 '05 #4

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

Similar topics

9
by: jwedel_stolo | last post by:
Hi I'm creating a dataview "on the fly" in order to sort some data prior to writing out the information to a MS SQL table I have used two methods in order to determine the sort order of the...
1
by: anon | last post by:
How does the DataView.Sort method really work under the covers? I know that it sorts a dataview, but what kind of sorting algorhythm is actually used? Thanks.
9
by: Raymond Lewallen | last post by:
I have a dataview in which the sort property will not sort the dataview. Here's is a simple scenario similar to what I am doing: Class Foo Private Function Retrieve() As DataView ' Returns a...
1
by: Jason | last post by:
I've gathered a bunch of data from Active Directory and placed it into a datatable ("ADTable"). I now need to sort and filter this table based on the selection of a drop down list("ddlCategory"). ...
1
by: Tony Papadimitriou | last post by:
Hi, Here's a short description of a problem that took me a couple of days to bypass (not solve): I update a table thru a dataview (or dataset, no difference in behavior for this problem) and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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
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...
0
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
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,...
0
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...

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.