*These
namespaces are must be required for SqlServer Connectivity in your web form:-
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
ShowDataUserID.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" " AutoEventWireup="true" CodeBehind="ShowDataUserID.aspx.cs" Inherits="ShowDataOnePage2010.ShowDataUserID" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<table style="width: 100%">
<tr>
<td colspan="2" style="width: 158px">
<asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC"
BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px"
ShowGridLines="True" Width="220px">
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
</asp:Calendar>
</td>
</tr>
<tr>
<td style="width: 158px">
<asp:LinkButton ID="LinkButtonLogout" runat="server" Font-Bold="True"
ForeColor="Maroon" onclick="LinkButtonLogout_Click">LogOut</asp:LinkButton>
</td>
<td style="width: 158px">
<asp:HyperLink ID="HyperLink1" runat="server" Font-Bold="True"
Font-Underline="True" ForeColor="Maroon" NavigateUrl="~/ShowAllData.aspx">ShowAllData</asp:HyperLink>
</td>
</tr>
</table>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table style="width: 100%">
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" />
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
</td>
</tr>
</table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">
<table style="width: 100%">
<tr>
<td>
</td>
</tr>
<tr>
<td>
<asp:AdRotator ID="AdRotator1" runat="server" DataSourceID="XmlDataSource1" />
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/App_Data/XMLFile1.xml"></asp:XmlDataSource>
</td>
</tr>
</table>
</asp:Content>
Web.Config File
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="ConnectionString" value="Server=PRADEEP-HP;Database=Decofloore2;User
Id=User_006;password=user006"/>
</appSettings>
</configuration>
ShowDataUserID.aspx.cs Page
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.Configuration;
namespace ShowDataOnePage2010
{
public partial class ShowAllData : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserName"] == null)
{
Response.Redirect("~/LoginSingleData.aspx");
}
string UserName = (string)Session["UserName"];
string StrCon = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection SqlConn = new SqlConnection(StrCon);
string StrSql = null;
StrSql = "Select
UserId,UserName,Address,PhoneNumber,State,City,Email,DateOfPurchasing,DateOfDelivery
from Registration where UserName='" +
UserName + "'";
SqlCommand SqlComm = new SqlCommand(StrSql, SqlConn);
SqlConn.Open();
SqlDataReader dr;
dr = SqlComm.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
SqlConn.Close();
}
Logout Button
protected void LinkButtonLogout_Click(object sender, EventArgs e)
{
Session.Abandon();
Session.Clear();
Session.Remove("UserName");
Session.RemoveAll();
Response.Redirect("~/LoginSingleData.aspx");
}
}
}
0 comments
Post a Comment