Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6080229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:02:15+00:00 2026-05-23T11:02:15+00:00

How do i sort data before display it to the repeater I wrote the

  • 0

How do i sort data before display it to the repeater
I wrote the code below and wonder how to sort the data by last name without depending on the sql server.
I would love to sort it by LINQ, it is possible. Can you give me an example on how to sort data base on my code.

WebForm

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <div>
        <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
                <table cellspacing="1"  border="1">
                    <tr>
                        <td>First Name</td>
                        <td>Last Name</td>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td><%# DataBinder.Eval(Container.DataItem, "FirstName") %> </td>
                    <td><%# DataBinder.Eval(Container.DataItem, "LastName") %> </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>
    </div>
</body>
</html>

Code behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

public class OFullName
{
    private string firstName;
    public string FirstName
    {
        get
        {
            return firstName;
        }
    }
    private string lastName;
    public string LastName
    {
        get
        {
            return lastName;
        }
    }
    public OFullName(string FirstName, string LastName)
    {
        firstName = FirstName;
        lastName = LastName;
    }
}

public partial class _Default : System.Web.UI.Page
{
    public static Random random = new Random();// The random number sequence
    private static string ShuffleString(string StringInput)
    {
             //Create new string from the reordered char array
            string rand = new string(StringInput.ToCharArray().
            OrderBy(s => (random.Next(2) % 2) == 0).ToArray());
        return rand;
    }

    protected void Page_Load(object sender, EventArgs e)
    {


        ArrayList xNames = new ArrayList();
        string TestString = "123ABCDEFGHIJK";
        for (int i = 1; i <= 10; i++)
        {
            xNames.Add(new OFullName(ShuffleString(TestString), ShuffleString(TestString)));
        }

        Repeater1.DataSource = xNames;//Add data from the Array list
        //How to sort data?
        Repeater1.DataBind();//Bind data

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:02:16+00:00Added an answer on May 23, 2026 at 11:02 am

    I would use generics:

    protected void Page_Load(object sender, EventArgs e)
    {
    
    
        var xNames = new List<OFullName>();
        string TestString = "123ABCDEFGHIJK";
        for (int i = 1; i <= 10; i++)
        {
            xNames.Add(new OFullName(ShuffleString(TestString), ShuffleString(TestString)));
        }
    
        Repeater1.DataSource = xNames.OrderBy(x => x.LastName); // sorts by last name Ascending. Use OrderByDesc to sort descending.
    
        Repeater1.DataBind();//Bind data
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to sort the data of a core data NSSet (I know
I am new with Linq and I would like to sort some data that
I have this big data-entry sort of page, a table kind of layout using
I have to sort out my data by some column, such that some specific
I have YAML data that looks sort of like this, but ~150k of it:
Comparison sort is opted for in most of the scenarios where data needs to
I'm trying to sort a column of data in a GTK tree view non-alphabetically.
With the sort of programs I write (working with raw file data) I often
I have an example class containing two data points: public enum Sort { First,
jQuery data grid with items&columns drag&drop, Items sort. Is there any? I need: Dragable\Dropable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.