Solved

Best way to sort controls in a gridview

Posted on 2008-10-08
19
249 Views
Last Modified: 2013-12-17
Please look at the attached bmp. When the user clicks "Select View" the items labeled "A" "E" "D" "C" "B" need to be sorted and should be in "B" "C" "D" "E" "A". All the controls under each letter (the dropdowns, checkboxes etc.) need to stay with te letter they're under. Whats the best way (or anyway) to sort these controls like i want? Currently i have a composite control with all the child controls in it and its on my aspx page 5 times, one for "A" one for "B" etc.
bigpage.bmp
0
Comment
Question by:troycomp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 9
19 Comments
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 22675550
Hi
Sorry I could see anything in your BMP
0
 

Author Comment

by:troycomp
ID: 22678286
Heres a bigger one
bigpage.bmp
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 22683306
Hi troycomp
In the main page 5 how are you calling this control by passing some values I take example you have A then the control gives the result and then pass E and it brings the results for e and so on?

If that is the case declare a Array and loop through it to pull the data in your composite and you can either declare other array for different order.

To achive this I am assuming that you composite control has a public paramater which when passed decide what results have to be shown.

Thanks

Harry
0
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 

Author Comment

by:troycomp
ID: 22683347
Hi harwantgrewal:

I have the composite control on my page 5 times. What results will be shown are based on what was loaded on another page. I have public properties but not like the one you described. They are not dynamic. Are you saying create the controls dynamically, declare an array and fill the array with the 5 composite controls, render them to the page and when the user clicks the sort checkbox, sort the array using array.reverse()?
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 22683526
When you say you have that composite control 5 times there must be some sort of desision happening what to display like A or E.?

And yes you are right render the composite control dynamically 5 times rather then putting it 5 times.

Harry
0
 

Author Comment

by:troycomp
ID: 22683533
Yes there is. And the controls will have to be created dynamically cause based on the search results, there may only be A thru C and not A thru E.
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 22683573
Still easy. Array can be dynamic :)
In your result you get to tables first one tells you what to display like "A" and "C" and you can make array of that and then display the results in your control.

Harry
0
 

Author Comment

by:troycomp
ID: 22683611
I'll give it a try and see what happens
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 22683617
Thanks I will wait for your reply.

Harry
0
 

Author Comment

by:troycomp
ID: 22683701
Harry:

I got it to reverse the order but i couldnt get it to reverse it to its original order. If i try Array.Sort i get "Failed to compare two elements in the array". Heres my code (Register is my composite control with my other controls (dropdowns, textboxes etc) in it.

  protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        Register rg = new Register[5];

        for (int i = 0; i < 5; i++)
        {
            rg[i] = new Register();

            rg[i].nameTextBox.Text = "Text " + i.ToString();
            rg[i].emailTextBox.Text = "Email " + i.ToString();
            Panel1.Controls.Add(rg[i]);
            Panel1.Controls.Add(new LiteralControl("<br/>"));
        }

    }
protected void Button1_Click(object sender, EventArgs e)
    {
        Array.Reverse(rg);

        for (int i = 0; i < 5; i++)
        {
            Panel1.Controls.Add(rg[i]);
            Panel1.Controls.Add(new LiteralControl("<br/>"));
        }

    }
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 22683716
Before Add those control you have to remove every control in your panel as you will be adding the same controls in a sort way.

Harry
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 22683745
moreover you are not checking for postbacks. I recommend you to care a function for inserting Register to your panel. And remember the life cycle in ASP.NET. One more thing your rg is not a global variable how can you access that in button  click?

Harry
0
 

Author Comment

by:troycomp
ID: 22683748
I just ttried that but got the same results
0
 

Author Comment

by:troycomp
ID: 22683764
It is global. i just wanted to show u what the name of it was
0
 

Author Comment

by:troycomp
ID: 22683778
why do i need to check for a postback?
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 22683911
Sorry for the delay reply.
No need to check postback on what link you get error when you do reverse?
Harry
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 22683929
Where is the code which makes the array back again in original order?
0
 

Accepted Solution

by:
troycomp earned 0 total points
ID: 22683944
Harry i'll work on this tomorrow  i'm tired from a llong work day.
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 22683953
No Problem, but its common problem with Sort Specially which this complex array object. Hope you will get up fresh and finish in one go :)
Thanks
Harry
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
QBCFMonitorService.exe randomly stops on Windows Server 2016 Essentials. 7 75
asp.net repeater 2 38
AJAX Create / Update Not working MVC 5 66
Adding Rows to Grid 4 33
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question