Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have an database table which have two columns "person name" and "status". "status" have value either VERIFIED or NOT VERIFIED. i want to bind repeater control to show verified persons first than repeat binding for not verified persons.
Posted
Updated 20-Aug-13 4:48am
v2
Comments
Please post some code and let us know where exactly you are facing.

1 solution

Design your repeater control

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Person.aspx.cs" Inherits="RepeaterExample.Person" %>

<!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>
    <form id="form1" runat="server">
    <div>
    <asp:Repeater ID="rptPerson" runat="server">
        <HeaderTemplate>
            <table>
                <tr>
                    <th>Person Name</th>
                    <th>Status</th>
                </tr>
        </HeaderTemplate>
        <ItemTemplate>
        <tr>
            <td><%# Eval("PersonName") %></td>
             <td><%# Eval("Status") %></td>
        </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>
    </div>
    </form>
</body>
</html>


Create your method for bind repeater using view like

C#
using System;
using System.Data;
using System.Data.SqlClient;

namespace RepeaterExample
{
    public partial class Person : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                RepeaterBind();
            }
            
        }
        private void RepeaterBind()
        {
            string connectionString = "Data Source=sandeepss-PC;Initial Catalog=CodeFirst;User ID=sa; Password=123456";
            SqlConnection con = new SqlConnection(connectionString);
            con.Open();
            SqlCommand cmd = new SqlCommand("Select * FROM Person", con);
            IDataReader dr = cmd.ExecuteReader();

            DataTable dt = new DataTable();
            dt.Load(dr);
            DataView dv = dt.DefaultView;
            dv.Sort = "Status DESC";
            rptPerson.DataSource = dv;
            rptPerson.DataBind();
           
        }
    }
} 
 
Share this answer
 
Comments
Abhishek Ginani 20-Aug-13 14:36pm    
Thank you very much sandeep singh... :-)
Sandeep Singh Shekhawat 21-Aug-13 2:04am    
Welcome dear Abhishek!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900