Login Page in ASP.net

To make a login page which would acess the database and tell the user that he has been loged on we will require a database table in which username and password is stored. This work will be done in 3 parts
First make a connection string Secondly accessing the data and thirdly loging in.

First we have to make a connection string the connection string is made in Web.Config like this

<connectionStrings>

<add name=”ConnectDBString” connectionString=”server=localhost;Database=test;Integrated Security=SSPI;” />

</connectionStrings>

by this we have made a connection string a connection string has 3 basic parts 1. Server Name 2. Database Name and 3. Authentication Type.
After making the connection string we have to get data from the database to get the data we will use connection less approach and we will get data by calling a stored procedure from database
To get data from database we write these lines to read the connection string from web.config

public db_data()
{
myConnectionString = ConfigurationManager.ConnectionStrings["ConnectDBString"].ConnectionString;

try
{
objcon = new SqlConnection(myConnectionString);
}

catch (Exception ex)
{

}
}

public DataTable Athuntication(string username, string password)
{
SqlCommand m_SqlCmd = new SqlCommand();
m_SqlCmd.CommandText = “dbo.[pr_select_login]”;
m_SqlCmd.CommandType = CommandType.StoredProcedure;
DataTable dtToReturn = new DataTable(“tbl_login”);
SqlDataAdapter m_SqlAdp = new SqlDataAdapter(m_SqlCmd);
m_SqlCmd.Connection = objcon;
try
{
m_SqlCmd.Parameters.Add(new SqlParameter(“@username”, SqlDbType.VarChar, 30, ParameterDirection.Input, false, 10, 0, “”, DataRowVersion.Proposed, username));
m_SqlCmd.Parameters.Add(new SqlParameter(“@password”, SqlDbType.VarChar, 50, ParameterDirection.Input, false, 10, 0, “”, DataRowVersion.Proposed, password));

m_SqlAdp.Fill(dtToReturn);
return dtToReturn;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return null;
}

}

}

Now we have a datatable full of required data we can use this for logging in.

Virtual Pagination and Scrolling with Fixed Headers in ASP.NET

Virtual Pagination and Scrolling with Fixed Headers in ASP.NET
by Muzzammil Hussain

Our generation is called the SMS generation we want each and everything fast and right at  tips of their fingers but wait do we have such a resources? We are in a far remote area with only 20kb Internet Speed you want to see a website which holds about a million records fetched from database so as soon as you will load that website what is going to happen? WAIT ! WAIT WAIT ! because it requires comparatively large amount of time. To solve this  new technique can be used which can do pagination and scrolling Virtually to accomplish this we have to work on both ends Database and the Code end. So first starting with the database we write a procedure

 

Create PROCEDURE [dbo].[GetStudents]
@PageIndex INT = 1
,@PageSize INT = 10
,@RecordCount INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SELECT ROW_NUMBER() OVER
(
ORDER BY [id] ASC
)AS RowNumber
,[id]
,[Name]
INTO #Results
FROM [Data]

SELECT @RecordCount = COUNT(*)
FROM #Results

SELECT * FROM #Results
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1

DROP TABLE #Results
END

 

Where DATA is the name of my table. This procedure also creates the number of pages and also allows the user to decide that how much records you need on the single page.

The magic in the project lies with the Jquery which sends a post back as soon as the scroll hits the end of the page

 

<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {

// $('form#mainForm').bind('submit', function (e) {
// e.preventDefault();
// checkForm();
// });

// $('input#hostName').focus();
function postback() {
<%= GetLoginPostBack() %>;
__doPostBack('Button1','');
}

$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
postback();
}
});

});
</script>

Now coming to the Actual Code of the Project

public partial class WebForm1 : System.Web.UI.Page
{
static string constring = @"Data Source=(local); Initial Catalog=NewHostel; Integrated Security=SSPI";
static DataTable tb = new DataTable();
static ArrayList checkPage = new ArrayList();
static int pageIndex;
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
DataTable dt = new DataTable("table");
dt.Columns.Add(new DataColumn("ID", Type.GetType("System.String")));
dt.Columns.Add(new DataColumn("Name", Type.GetType("System.String")));
Session["ss"] = dt;
ShowStudentsNewHostelPageWise(1);
checkPage.Add(1);

}

}

c#final

The detail of the code is as following

There is a list box available at the top of the page you can select how much records you want as soon as the value is changes the list box event calls the procudre and creates the number of pages depending upon the records. now you have two options that you can even select next records for the page by click on page it would fetch the new records and will append it to the older grid view and also as soon as you take the scroll down and hit the end it again fetch the records from database and append them to lower end of girdview.