Sorting a table using hidden field

D

Dan

I am reposting a question from about 3 weeks ago ("sorting capability").

I have an aspx page in which I get the data from a database dynamically,
through C# code, by creating a dynamic table using TableHeaderCell and
TableHeaderRow.
The data is binded to the table by using a DataSet and Data Reader.

The responses on the forum made me think that it would be easier to sort the
data in the table (when clicking on the header column), by adding a hidden
field in the aspx form and getting the clicked sorting column (expression) in
C#, create a sorting clause.

Probably it is a easy question, but I am new to designing with C# and .NET
framework.

Does anybody know what is the .NETmethod or property of the
DataSET,SQLAdapter or Reader which has to be used to get the value from the
hidden field to sort ASC or DESC ?

I know that first I have to create the value:

string sort = this.hiddenfield.value
if (sort=="column_clicked_value")
{
..........??????????
//How to rebind and sort ASC or DESC?

}

Can anybody help me please?

Thank you.

Dan
 
R

raylopez99

I am reposting a question from about 3 weeks ago ("sorting capability").

I have an aspx page in which I get the data from a database dynamically,
through C# code, by creating a dynamic table using TableHeaderCell and
TableHeaderRow.
The data is binded to the table by using a DataSet and Data Reader.

The responses on the forum made me think that it would be easier to sort the
data in the table (when clicking on the header column), by adding a hidden
field in the aspx form and getting the clicked sorting column (expression) in
C#, create a sorting clause.

Probably it is a easy question, but I am new to designing with C# and .NET
framework.

Does anybody know what is the .NETmethod or property of the
DataSET,SQLAdapter or Reader which has to be used to get the value from the
hidden field to sort ASC or DESC ?

I know that first I have to create the value:

string sort = this.hiddenfield.value
if (sort=="column_clicked_value")
{
.........??????????
//How to rebind and sort ASC or DESC?

}

Can anybody help me please?

Thank you.

Dan

Dan,

Ideally, I would continue to study the language and learn myself
without asking others.

Seems to me that you need to write a SQL language query that will do
ASC or DESC, and incorporate this query into your .NET code. Though
it's true that the SQL query will be handled by the back end rather
than the front end, it's also true SQL is more stable and likely
somebody years from now can read your code without a problem, unlike
the road you're traveling now.

If you don't like that suggestion, and insist on working with the
front end, then why don't you quit trying to figure out if
DataSET,SQLAdapter or Reader has a sorting function (and I assume
you've looked at the help topics on what members they have), and
instead just use a standard C# generic collection class in your own
class to sort, like a List or Array and use Quicksort/ Sort on it?

BTW the SQL adapter and the like are complex pieces of code that you
should only use to do the data binding and back and forth that they
provide, and you should not overload them to do sorting stuff, IMO.
Also learning C# on the front end for dB design is frustrating because
there appears to me (and I'm not an expert) lots of undocumented
casting using the "As" operator, and the like. Or so it seems (in my
mind's eye).

Hope this was "helpful".

Ray
 
C

Ciaran O''Donnell

You need to make a DataView from the DataTable.
E.g
DataTable table;
DataView view = table.DefaultView;
view.Sort = "ColumnToSortBy ASC";

Then use the DataView as the binding source.
 
C

Ciaran O''Donnell

This post doesnt seem very helpful apart from the suggestion of sorting a
list held in an array. People often post here when they have tried everything
they can think of to get around a problem and there are a lot of people here
who are happy to help. This forum is supposed to be a .NET community and that
means people are here to help each other learn more about .NET.
I understand that it is obviously preferable for people to figure out the
issues they have on their own as it will help them in the future if they dont
have access to a resource like this, but there have been times in my career
where I have wanted to ask a question in a place like this to make sure I am
not re-inventing the wheel.
It would make this forum a friendlier place if you could limit your posts to
simply trying to help people rather than making them feel bad for asking
their questions here. Try reading the responses that the MVP's give in these
forums and notice they are normally in a friendly and supportive tone.
 
R

raylopez99

Try reading the responses that the MVP's give in these
forums and notice they are normally in a friendly and supportive tone.

Yeah, like Peter Dunohoe? Or whatever his name is. He claims to be
an MVP. And my advice BTW was good--perhaps not as good as yours, but
still good.

Thanks, for making me feel bad.

RL
 
C

Ciaran O''Donnell

Peter Duniho isnt an MVP and doesnt put MVP on the end of him name and I
havent seem him claim to be an MVP.
Your advice was good and I did say that in my post. My point was that making
the OP feel bad for asking here rather than finding it out himself was not
necessary.
I had no intention of making you feel bad, I just wanted to point out my
opinion on these forums and the people that seek help here.
 
R

raylopez99

Peter Duniho isnt an MVP and doesnt put MVP on the end of him name and I
havent seem him claim to be an MVP.

Yes he is. Or so he says, earlier this week in a thread:
[...]
Speaking of poor programmer, I see Ben Voight has the prestigious [C++
MVP] abbreviation next to his name--funny, I don't see that next to
your name.

[Peter Duniho] That's true, you don't. While I am in fact a recipient
of the C# MVP
award, I choose not to include that in my posting credentials. So
what?
--
Your advice was good and I did say that in my post. My point was that making
the OP feel bad for asking here rather than finding it out himself was not
necessary.
I had no intention of making you feel bad, I just wanted to point out my
opinion on these forums and the people that seek help here.

Don't worry about it. I'm only being a polarizing author, sometimes
pejoratively called a troll, which gets more replies (wheel,
squeeking, etc).

And thanks for your input. I code for fun but appreciate professionals
or near professionals like yourself (and Peter, and Jon, and Ben,
etc).

RL
 

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

Top