Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i'm developing an Matrimony Website.

At Present i didn't set ant criteria.Who ever visit my page he/she can see all the available profiles.


Actually now what i want is,once the the user is jump into the site he can see only 50 profiles initially.if he click the next button after reach 50 it should check whether the user is logged in if he has logged in it should takes him to next page else it should say as "please login".

Can anyone help me to achieve this?


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class brideview : System.Web.UI.Page
{
    
    string cmd;
    int pos;
    string gender, from, to, religion,category;
    protected void Page_Load(object sender, EventArgs e)
    {
        gender = Request.QueryString["Gender"].ToString();
        from = Request.QueryString["from"].ToString();
        to = Request.QueryString["to"].ToString();
        religion = Request.QueryString["religion"].ToString();
        category = Request.QueryString["category"].ToString();
        if (!IsPostBack)
        {
            ViewState["vs"] = 0;
        }
        pos = (int)this.ViewState["vs"];
        listing();

    }
    void listing()
    {
        try
        {
            cmd = "select distinct r.id,r.name,r.age,'~/TB_Photos/'+[PhotoName] as Url, '~/Photos/'+[PhotoName] as ImageFullUrl,r.Religion,r.landline,r.e_mail,r.country,p.education,p.income,p.occupation from registration r inner join profession p on p.id=r.id where Gender='" + gender + "' and status='active'";
            if (from.ToString() != "--Select--" && to.ToString() != "--Select--")
            {
                cmd = cmd + " and age between " + Convert.ToInt32(from) + " and " + Convert.ToInt32(to);
            }
            if (religion.ToString() != "--Select--")
            {
                cmd = cmd + " and religion='" + religion + "'";
            }
            if (category.ToString() != "--Select--")
            {
                cmd = cmd + " and occupation='" + category + "'";
            }
            cmd = cmd + " order by id desc";
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
            con.Open();
            SqlDataAdapter dadapter;
            dadapter = new SqlDataAdapter(cmd, con);
            DataSet dset = new DataSet();
            PagedDataSource adsource = new PagedDataSource();
            dadapter.Fill(dset);
            adsource.DataSource = dset.Tables[0].DefaultView;
            adsource.PageSize = 50;
            adsource.AllowPaging = true;
            adsource.CurrentPageIndex = pos;
            lbtnPrev.Enabled = !adsource.IsFirstPage;
            lbtnNext.Enabled = !adsource.IsLastPage;
            DataList1.DataSource = adsource;
            DataList1.DataBind();

            con.Close();
            con.Dispose();

        }
        catch (Exception ex)
        {

            //Response.Write(ex.Message);
        }
    }
    protected void lbtnPrev_Click(object sender, EventArgs e)
    {
        pos = (int)this.ViewState["vs"];
        pos -= 1;
        this.ViewState["vs"] = pos;
        listing();
    }
    protected void lbtnNext_Click(object sender, EventArgs e)
    {
        if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
        {
            pos = (int)this.ViewState["vs"];
            pos += 1;
            this.ViewState["vs"] = pos;
            listing();
        }
    }
}


This is my code...

when i click
lbtnNext_Click
it should verify that the user is logged in or not?
is there any eg: for using session.

I dont know how and where to use session :(


Thanks in advance.
Posted
Updated 9-Mar-14 23:22pm
v2

You should use session for this.
 
Share this answer
 
Comments
Krunal Rohit 10-Mar-14 4:41am    
Like how, when and where ??

-KR
hi the Following code works for me:

C#
if (Session["UserAuthentication"] != null)
        {
            pos = (int)this.ViewState["vs"];
            pos += 1;
            this.ViewState["vs"] = pos;
            listing();
        }
        else
        {
            Response.Write("Please login to view more details");
            Response.Redirect("Login.aspx");
        }
 
Share this answer
 

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