Sunday, 6 January 2013

Login example using stored procedure in asp.net Part-1.


In this I will explain login example using stored procedure in asp.net.

After  good reponse of my previous post “ Login xample in asp.net”  , I have decide to write a post for login using stored procedure in asp.net. You will be familier to stored procedure because I have used many procedure in my previous post. So I think that you know how to create stored procedure in sql server . In this post I will explaine each and every thing in simple language.
 First create three tables in sqlserver.
1     1.)    First Table :- checkUser

CREATE TABLE [dbo].[checkUser](
     [userName] [nvarchar](50) NOT NULL,
     [pass] [nvarchar](50) NOT NULL
        )

2    2.)    Second Table :- checkUserAvailability
CREATE TABLE [dbo].[userNameAvailability](
     [userName] [nvarchar](50) NOT NULL
)

3    3.)    Third Table :- newUser
CREATE TABLE [dbo].[newUser](
     [userName] [nvarchar](50) NOT NULL,
     [firstName] [nvarchar](50) NOT NULL,
     [lastName] [nvarchar](50) NOT NULL,
     [pass] [nvarchar](50) NOT NULL,
     [emailId] [nvarchar](50) NOT NULL,
     [securityQuestion] [nvarchar](50) NOT NULL,
     [answer] [nvarchar](50) NOT NULL
)

After that create a stored procedure for these three tables.  Here  I will use stored procedure because procedure have amny advantages over simple sql query.
Advantage of stored procedure:-
Click here .
Now it’s time to make stored procedure:-
For  Table checkUser:-
CREATE PROCEDURE sp_checkUser
(
@userName varchar(50),
@pass varchar(50)
)
AS
BEGIN
     select * from checkUser where userName=@userName and pass=@pass;
END
            GO
For Table userNameAvailability :-
CREATE PROCEDURE sp_userNameAvailability
(
@userName varchar(50)
)
AS
BEGIN
     select * from userNameAvailability where userName=@userName;
END
            GO
For Table newUser :-
CREATE PROCEDURE sp_newUser
(
@userName varchar(50),
@firstName varchar(50),
@lastName varchar(50),
@pass varchar(50),
@emailId varchar(50),
@securityQuestion varchar(50),
@answer varchar(50)
)
AS
BEGIN
     insert into newUser(userName,firstName,lastName,pass,emailId,securityQuestion,answer) values(@userName,@firstName,@lastName,@pass,@emailId,@securityQuestion,@answer);
END
            GO
                                                                                                      to be continued………

Friday, 4 January 2013

Download jquery-1.7.2.min.js or jquery-1.8.2.min.js file

In this post I have given a link to download jquery 1.7.2.min.js and 1.8.2.min.js file.

Download Links:-

For 1.7.2.min.js :- jquery1.7.2.min.js or click here
For 1.8.2.min.js :- jquery-1.8.2.min.js or click here 

Saturday, 29 December 2012

Calculate total sum of columns in gridview footer using c# in Asp.net.


In this post I will explain Hoe to calculate total sum of columns in gridview footer using c# in Asp.Net.

Description:-

I have to show total sum of columns in griview footer.  So take one gridview control on your page and show footer(Initially it’s visibily is false). Create one database table with a name EmpSalary  like this.

ColumnName
DataType
EmpId
Int(primary key)
EmpName
Varchar(50)
DeptId
Int
Salary
Varchar(50)

Insert some Dummy data into the table.

Now create Design page like this.

Default.aspx:-

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="true" PageSize="5"
            BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
            CellPadding="3" CellSpacing="2" DataSourceID="SqlDataSource1"
            ShowFooter="True" onrowdatabound="GridView1_RowDataBound">
            <Columns>
                <asp:BoundField DataField=" EmpId " HeaderText="EmpId" SortExpression=" EmpId " />
                <asp:BoundField DataField=" EmpName " HeaderText="EmpName"
                    SortExpression=" EmpName " />
                    <asp:TemplateField HeaderText="DeptId">
                    <ItemTemplate >
                        <asp:Label ID="lblDeptId" runat="server" Text='<%#Eval("DeptId") %>'></asp:Label>
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:Label ID="lblTotalAmount" runat="server" Text="Total Amount"></asp:Label>
                    </FooterTemplate>
                    </asp:TemplateField>
               <asp:TemplateField HeaderText="Salary">
                    <ItemTemplate >
                        <asp:Label ID="lblSalary" runat="server" Text='<%#Eval("Salary") %>'></asp:Label>
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:Label ID="lblTotal" runat="server" ></asp:Label>
                    </FooterTemplate>
                    </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#FFF1D4" />
            <SortedAscendingHeaderStyle BackColor="#B95C30" />
            <SortedDescendingCellStyle BackColor="#F1E5CE" />
            <SortedDescendingHeaderStyle BackColor="#93451F" />

        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:modiConnectionString %>"
            SelectCommand="SELECT [EmpId], [EmpName], [DeptId], [Salary] FROM [EmpSalary]">
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>

After  completion of design page write the code in codebehind.

Default.aspx.cs:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default : System.Web.UI.Page
{
    int total = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Salary"));
        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lbltotalAmount = (Label)e.Row.FindControl("lblTotal");
            lbltotalAmount.Text = total.ToString();
        }

    }
}

Your ouput should be like this.


Tuesday, 25 December 2012

Pagination in SQL Server 2008.


In this I will explain Pagination in sql server 2008.
Please follow the steps:-
Open  sql server 2008 Management studio à create a new Database à create a table like this
Create table Details (Id int primary key , Name varchar(50), Country varchar(50));
Now insert the dummy data in the table.
Here I am inserting 1000 data one at a time. See the code given below ..
declare @count int=1;
declare @max int=5000;
delete from Details;
while(@count<=@max)
begin
insert into Details(Id,Name,Country)
select @count ,'Name'+CAST(@count as varchar(5)),'Country'+CAST(@count as varchar(5))
set @count=@count+1
end
This will insert 1000 data in the table.

Now create a stored procedure .
CREATE PROCEDURE PaginationIn2008
(
@start int=1,
@end int=500
)
AS
BEGIN
      select * from Details where Id between @start and @end
      order by Id
END
GO
Execute stored procedure.
To get data from 1 to 10 , execute the procedure like this
exec PaginationIn2008 1,10


If you want 100 to 200 , execute the procedure like this.
exec PaginationIn2008 100,200

Monday, 24 December 2012

Hello message in MVC2.0 in .Net.


In this post I will explain  how to print Hello message in MVC2.0 in .NET.
First create a new Asp.net MVC2.0 project in visual studio 2010.
 Select the visual studio c#/web Template group on left , then choose the “ASP.NET MVC 2 Empty Web Application” , name the project and click ok button.
Go to solution explorer  -> right click on controller folder ->  select add  ->  click on Controller -> give a controller name i.e HomeController -> click Add button . This will create HomeController.aspx.cs page with the following code like this.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcHello.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View();
        }

    }
}
  
Let change the following two thing in the above code
·         Change the method to return a string instead of ActionResult
·         Change the return statement to return “Hello From Home”.
After changing the two thing the code will look like this:
        public string Index()
        {
            return "Hello From Home";
        }

Now it’s time to run the code. So press F5.

Sunday, 23 December 2012

Large Image Preview on mouseover in Jquery in Asp.Net.


In this post I will explain Image Preview on mouseover in Jquery in Asp.Net.
Jquery Code:-
<script type="text/javascript" src="../Scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" >
        $(document).ready(function () {
            ImagePreview();
        });
        function ImagePreview() {
            xOffset = -25;
            yOffset = 50;
            $("a.preview").hover(function (e) {
                this.t = this.title;
                this.title = "";
                var c = (this.t != "") ? "<br/>" + this.t : "";
                $("body").append("<p id='preview'><img src='" + this.href + "' alt='Image Preview' />" + c + "</p>");
                $("#preview")
            .css("top", (e.pageY - xOffset) + "px")
            .css("left", (e.pageX + yOffset) + "px")
            .fadeIn("fast");
            },

            function () {
                this.title = this.t;
                $("#preview").remove();
            });
            $("a.preview").mousemove(function (e) {
                $("#preview")
        .css("top", (e.pageY - xOffset) + "px")
        .css("left", (e.pageX + yOffset) + "px");
            });
        };
    </script>

Design.aspx:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="../Scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" >
        $(document).ready(function () {
            ImagePreview();
        });
        function ImagePreview() {
            xOffset = -25;
            yOffset = 50;
            $("a.preview").hover(function (e) {
                this.t = this.title;
                this.title = "";
                var c = (this.t != "") ? "<br/>" + this.t : "";
                $("body").append("<p id='preview'><img src='" + this.href + "' alt='Image Preview' />" + c + "</p>");
                $("#preview")
            .css("top", (e.pageY - xOffset) + "px")
            .css("left", (e.pageX + yOffset) + "px")
            .fadeIn("fast");
            },

            function () {
                this.title = this.t;
                $("#preview").remove();
            });
            $("a.preview").mousemove(function (e) {
                $("#preview")
        .css("top", (e.pageY - xOffset) + "px")
        .css("left", (e.pageX + yOffset) + "px");
            });
        };
    </script>
    <style type="text/css">
    #preview
    {
       position:absolute;
       border:none;
       background:gray;
       padding:2px;
       display:none;
       color:Gray;
       box-shadow:4px 4px 4px rgba(105,116,130,1);
    }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DataList ID="DataList1" runat="server" RepeatColumns="4" CellPadding="5">
        <ItemTemplate>
            <asp:HyperLink ID="HyperLink1" runat="server" class="preview" ToolTip='<%#Bind("Name") %>' NavigateUrl='<%#Bind("Name","image/{0}") %>' >
            <asp:Image ID="Image1" runat="server" ImageUrl='<%#Bind("Name","image/{0}") %>' /></asp:HyperLink>
        </ItemTemplate>
        </asp:DataList>
    </div>
    </form>
</body>
</html>

Design.aspx.cs:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;

public partial class jquery_ImagePreview : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDataList();
        }
    }
    public void BindDataList()
    {
        DirectoryInfo dirInfo = new DirectoryInfo(MapPath("image"));
        FileInfo[] file = dirInfo.GetFiles();
        ArrayList arrList = new ArrayList();
        foreach (FileInfo info in file)
        {
            arrList.Add(info);
        }
        DataList1.DataSource = arrList;
        DataList1.DataBind();
    }
}