DataView.sort does not work thru LinkButton

N

nish

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
 
N

nish

Hi Gopal,

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

lnkHeader.CommandName = "Sort" + i;
lnkHeader.CommandArgument = "Descending";
lnkHeader.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.
 
G

Gopal \(FMS, Inc.\)

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/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top