Vibhu Aggarwal .Net Notes

Project 2011

Syllabus of Project Development


  1. Synopsis
    1. Analysis & Requirement
    2. E-R Diagram
    3. DFD
    4. Screenshot
    5. Design Complete Synopsis
  1. Data Base
    1. Create table
    2. Constraints
    3. Stored Procedure
    4. View
    5. Cursor
    6. Trigger
  1. Design Phase in Asp.Net
    1. Table tag
    2. CSS(Cascading Style Sheets)
    3. Complete Designing in Div tag without table tag

Using CSS.

  1. Master Page
  2. Menu with web.sitemap
  3. TreeView with web.sitemap
  4. SiteMapDataSource
  5. MVC(Model View Controller) Pattern
  1. Server Control
    1. Textbox,Button
    2. RadioButton & CheckBox
    3. Panel & HiddenField
    4. DropDownList & ListBox
    5. Table Control
    6. Repeater
    7. DataList
    8. GridView
  1. User  Control
  2. Custom Control
  3. Html Control
  4. JavaScript & Ajax Complete
  5. State management
  6. crystal report
  7. xml
  8. MS chart

Check All Feature Implement in every student’ Project

Check Status of every student ‘s project time to time

Date 12 feb 2011

Masterpage.aspx

<%@ Master Language=”C#” AutoEventWireup=”true” CodeFile=”MasterPage.master.cs” Inherits=”MasterPage” %>

DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

xmlns=”http://www.w3.org/1999/xhtml“>
<head runat=”server”>
<title>ANKIT</title>
css/StyleSheet.css”type=”text/css”rel=”stylesheet” />
ContentPlaceHolder id=”head” runat=”server”>
ContentPlaceHolder>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<div>Header<asp:Menu ID=”Menu1″  Orientation=”Horizontal” runat=”server”
BackColor=”#FFFBD6″ DynamicHorizontalOffset=”2″ Font-Names=”Verdana”
Font-Size=”0.8em” ForeColor=”#990000″ onmenuitemclick=”Menu1_MenuItemClick”
StaticSubMenuIndent=”10px” DataSourceID=”SiteMapDataSource1″>
<StaticSelectedStyle BackColor=”#FFCC66″ />
<StaticMenuItemStyle HorizontalPadding=”5px” VerticalPadding=”2px” />
<DynamicHoverStyle BackColor=”#990000″ ForeColor=”White” />
<DynamicMenuStyle BackColor=”#FFFBD6″ />
<DynamicSelectedStyle BackColor=”#FFCC66″ />
<DynamicMenuItemStyle HorizontalPadding=”5px” VerticalPadding=”2px” />
<StaticHoverStyle BackColor=”#990000″ ForeColor=”White” />
</asp:Menu>
SiteMapDataSource ID=”SiteMapDataSource1″ runat=”server” />
</div>
<asp:ContentPlaceHolder id=”ContentPlaceHolder1″ runat=”server”>

</asp:ContentPlaceHolder>
</div>
form>
<div>Footer</div>
</body>
</html>

.css

.DivHeader
{
width:100%;
height:100px;
background-color:Blue;
}
.DivFooter
{
width:100%;
height:100px;
background-color:Green;
}

web.sitemap

xml version=”1.0″ encoding=”utf-8″ ?>
<siteMap xmlns=”http://schemas.microsoft.com/AspNet/SiteMap-File-1.0” >
<siteMapNode url=”Default.aspx” title=”Default”  description=”Default”>
<siteMapNode url=”Default2.aspx” title=”Default2″  description=”Default2″ />
<siteMapNode url=”” title=””  description=”” />
</siteMapNode>
</siteMap>

date 13 feb 2011

Understanding ASP.NET MVC (Model View Controller) Architecture for Beginners

By kiran dangar | 26 Jan 2010

Learning ASP.NET MVC (Model View Controller) architecture and fundamentals for beginners

Top of Form

Introduction

This article is intended to provide basic concepts and fundamentals of ASP.NET MVC (Model View Controller) architecture workflow for beginners.

“M” “V” “C” stands for “MODEL” “VIEW” “CONTROLLER”. ASP.NET MVC is an architecture to develop ASP.NET web applications in a different manner than the traditional ASP.NET web development. Web applications developed with ASP.NET MVC are even more SEO (Search Engine) friendly.

Developing ASP.NET MVC application requires Microsoft .NET Framework 3.5 or higher.

MVC Interaction with Browser

Like a normal web server interaction, MVC application also accepts requests and responds to the web browser in the same way.

Inside MVC Architecture

The entire ASP.NET MVC architecture is based on Microsoft .NET Framework 3.5 and in addition uses LINQ to SQL Server.

What is a Model?

  1. MVC model is basically a C# or VB.NET class
  2. A model is accessible by both controller and view
  3. A model can be used to pass data from Controller to view
  4. A view can use model to display data in page.

What is a View?

  1. View is an ASPX page without having a code behind file
  2. All page specific HTML generation and formatting can be done inside view
  3. One can use Inline code (server tags ) to develop dynamic pages
  4. A request to view (ASPX page) can be made only from a controller’s action method

What is a Controller?

  1. Controller is basically a C# or VB.NET class which inherits system.mvc.controller
  2. Controller is a heart of the entire MVC architecture
  3. Inside Controller’s class action methods can be implemented which are responsible for responding to browser OR calling views.
  4. Controller can access and use model class to pass data to views
  5. Controller uses ViewData to pass any data to view

MVC File Structure & File Naming Standards

MVC uses a standard directory structure and file naming standards which are a very important part of MVC application development.

Inside the ROOT directory of the application, there must be 3 directories each for model, view and Controller.

Apart from 3 directories, there must have a Global.asax file in root folder, and a web.config like a traditional ASP.NET application.

  • Root [directory]
    • Controller[directory]
      • Controller CS files
    • Models[directory]
      • Model CS files
    • Views [directory]
      • View CS files
    • Global.asax
    • Web.config

ASP.NET MVC Execution Life Cycle

Here is how MVC architecture executes the requests to browser and objects interactions with each other.

A step by step process is explained below [Refer to the figure as given below]:

Browser Request (Step 1)

Browser request happens with a specific URL. Let’s assume that the user enters URL like: [xyz.com]/home/index/

Job of Global.asax – MVC routing (Step 2)

The specified URL will first get parsed via application_start() method inside Global.asax file. From the requested URL, it will parse the Controller, Action and ID.

So for [xyz.com]/home/index/:

  • Controller = home
  • Action = index()
  • ID = empty — we have not specified ID in [xyz.com]/home/index/, so it will consider as empty string

Controller and Action methods (Step 3)

MVC now finds the home controller class in controller directory. A controller class contains different action methods,

There can be more than one action method, but MVC will only invoke the action method which has been parsed from the URL, its index() in our case.

So something like: homeController.index() will happen inside MVC controller class.

Invoking action method can return plain text string OR rendered HTML by using view.

Call to View (Step 4)

Invoking view will return view(). A call to view will access the particular ASPX page inside the view directory and generate the rendered HTML from the ASPX and will respond back to the browser.

In our case, controller was home and action was index(). So calling view() will return a rendered HTML from the ASPX page located at /views/home/index.aspx.

This is it, the whole process ends here. So this is how MVC architecture works.

Bottom of Form

Mvc Pattern & Dropdownliast Control

.aspx

<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

xmlns=”http://www.w3.org/1999/xhtml“>
<head runat=”server”>
<title></title>

.style1
{
width: 100%;
}
</style>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>

<table>
<tr>
<td>
State</td>
<td>
DropDownList ID=”ddlState” runat=”server” AutoPostBack=”True”
onselectedindexchanged=”findStateId” Width=”100px”>
DropDownList>
</td>
</tr>
<tr>
<td>
City</td>
<td>
DropDownList ID=”ddlCity” runat=”server” Width=”100px”>
DropDownList>
</td>
</tr>
</table>

</div>
form>
</body>
</html>
.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
{
dal d;
public _Default()
{
d = new dal();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillState();
}

}
protected void fillState()
{
ddlState.DataSource = d.fillState();
ddlState.DataTextField = “StateName”;
ddlState.DataValueField = “StateId”;
ddlState.DataBind();
ddlState.Items.Insert(0, “Select”);
ddlCity.Items.Insert(0, “Select”);

}

protected void findStateId(object sender, EventArgs e)
{
ddlCity.DataSource = d.fillCity(Convert.ToInt32(ddlState.Text));
ddlCity.DataTextField = “CityName”;
ddlCity.DataValueField = “CityId”;
ddlCity.DataBind();
ddlCity.Items.Insert(0, “Select”);
}
}
dal.cs
using System;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for dal
/// </summary>
public class dal
{
SqlConnection con;
SqlDataAdapter adap;
DataSet ds;
public dal()
{
con = new SqlConnection(“initial catalog=abhi;integrated security=yes”);
ds = new DataSet();
}
public DataSet fillState()
{
adap = new SqlDataAdapter(“select * from state”,con);
adap.Fill(ds,”state”);
return ds;
}
public DataSet fillCity(int stateId)
{
adap = new SqlDataAdapter(“select * from city where fkStateId=”+stateId+””, con);
adap.Fill(ds, “city”);
return ds;
}
}

date 27/02/2011

batch A

using System;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader rd;
public _Default()
{
con = new SqlConnection(“initial catalog=newgen;integrated security=yes”);
con.Open();
}
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
cmd = new SqlCommand(“select logintype from userlogin where loginid=’”+TextBox1.Text+”‘ and password=’”+TextBox2.Text+”‘”,con);
rd=cmd.ExecuteReader();
bool b =rd.Read();
if (b == true)
{
if (rd[0].ToString() == “admin”)
{
Session["username"] = TextBox1.Text;
Response.Redirect(“search.aspx”);
}
else if (rd[0].ToString() == “user”)
{
Session["username"] = TextBox1.Text;
Response.Redirect(“contactus.aspx”);
}

}
else
{
Label1.Text = “please insert correct loginid and password”;
}
}
}

Date 27/02/2011

Batch B

.aspx.cs

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;publicpartial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void Button1_Click(object sender, EventArgs e)

{

bl b = new bl();

b.EmpId = Convert.ToInt32(TextBox1.Text);

if (b.EmpId == 0)

{

Response.Write(b.msg.ToString());

}

else

{

Response.Write(b.EmpId.ToString());

}

}

}

bl.cs

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;///<summary>///Summary description for bl///</summary>publicclass bl

{

int empId;

public string msg;

public int EmpId

{

get

{

return empId;

}

set

{

if (value < 999)

{

empId = value;

}

else

{

msg=“please insert below 999″;

}

}

}

}

Batch ‘A’
Date 5/3/2011
updation in gridview

.aspx

<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

xmlns=”http://www.w3.org/1999/xhtml“>
<head runat=”server”>
<title></title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
GridView ID=”GridView1″ OnRowUpdating=”updaterecord” OnRowCancelingEdit=”cancelrecord” OnRowEditing=”editrecord” AutoGenerateColumns=”false” runat=”server”>
<Columns>
TemplateField HeaderText=”Emp Id”>
<ItemTemplate>
lblEmpId” runat=”server” Text=” >
</ItemTemplate>
TemplateField>
TemplateField HeaderText=”Emp Name”>
<ItemTemplate>

</ItemTemplate>
<EditItemTemplate>
TextBox ID=”txtEmpName” runat=”server” Text=”>
TextBox>
</EditItemTemplate>
TemplateField>
TemplateField HeaderText=”Emp Salary”>
<ItemTemplate>

</ItemTemplate>
<EditItemTemplate>
TextBox ID=”txtEmpSalary” runat=”server” Text=”>
TextBox>
</EditItemTemplate>
TemplateField>
TemplateField HeaderText=”Operation”>
<ItemTemplate>
<asp:Button ID=”btnEdit” CommandName=”Edit” runat=”server” Text=”Edit” />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID=”btnUpdate” runat=”server” Text=”Update” CommandName=”update” />
<asp:Button ID=”btnCancel” CommandName=”cancel” runat=”server” Text=”Cancel” />
</EditItemTemplate>
TemplateField>
</Columns>
GridView>
</div>
form>
</body>
</html>
.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader rd;
public _Default()
{
con = new SqlConnection(“initial catalog=abhi;integrated security=yes”);
con.Open();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillGrid();
}
}
void fillGrid()
{
con.Close();
con.Open();
cmd = new SqlCommand(“select * from Employee”,con);
rd =cmd.ExecuteReader();
GridView1.DataSource = rd;
GridView1.DataBind();
}
protected void editrecord(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
fillGrid();
}
protected void cancelrecord(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
fillGrid();
}
protected void updaterecord(object sender, GridViewUpdateEventArgs e)
{
Label lblEmpId =GridView1.Rows[e.RowIndex].FindControl(“lblEmpId”) as Label;
TextBox txtEmpName =GridView1.Rows[e.RowIndex].FindControl(“txtEmpName”) as TextBox;
TextBox txtEmpSalary = GridView1.Rows[e.RowIndex].FindControl(“txtEmpSalary”) as TextBox;
con.Close();
con.Open();
cmd = new SqlCommand(“update Employee set EmpName=’”+txtEmpName.Text+”‘ , EmpSalary=”+Convert.ToDecimal(txtEmpSalary.Text)+” where EmpId=”+Convert.ToInt32(lblEmpId.Text)+” “,con);
int t =cmd.ExecuteNonQuery();
if (t>0)
{
GridView1.EditIndex = -1;
fillGrid();

}

}
}

Batch ‘B’
Date 5/2/2011

.aspx

<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

xmlns=”http://www.w3.org/1999/xhtml“>
<head runat=”server”>
css/StyleSheet.css” rel=”Stylesheet” type=”text/css” />
<title></title>
</head>
<body>
<form id=”form1″ runat=”server”>
<%–<table >
<tr >
<td >rtr</td>
<td >trtr</td>
</tr>
<tr>
<td >rtt</td>
<td >rtr</td>
</tr>

</table>–%>
<div >

ID=”TextBox4″ runat=”server”>
TextBox

ID=”TextBox3″  runat=”server”>
</div>
<div >

TextBox

ID=”TextBox2″ runat=”server”>
<div >
TextBoxID=”TextBox1″ runat=”server”>

</div>

form>
</body>
</html>
.css

.row
{
width:300px;
margin-top:10px;
margin-bottom:10px;
}
.row input
{
width:100px;
background-color:Blue;
height:20px;

}
.columnleft
{
width:100px;
float:left;
background-color:Gray;
margin-left:5px;
margin-top:10px;
}

.columnright
{
width:100px;
float:right;
background-color:Gray;
margin-left:5px;
margin-top:10px;
}

btach  ‘A’

date 13–3-2011

.aspx
<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

cc1″ %>

Src=”~/WebUserControl.ascx” TagPrefix=”uc1″ TagName=”detail” %>
DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

xmlns=”http://www.w3.org/1999/xhtml“>
<head runat=”server”>
<title></title>
<link href=”App_Themes/css/StyleSheet.css” rel=”Stylesheet” type=”text/css” />
</head>
<body>
<form id=”form1″ runat=”server”>
ScriptManager ID=”ScriptManager1″ runat=”server”>
</asp:ScriptManager>
<asp:Button ID=”Button1″ runat=”server” Text=”Show” />
<div>
<asp:Panel ID=”p1″ runat=”server” style=”display:none;” >
<uc1:detail ID=”ucdetail” runat=”server” />
</asp:Panel>
</div>

<cc1:ModalPopupExtender TargetControlID=”Button1″ PopupControlID=”p1″
BackgroundCssClass=”background” ID=”ModalPopupExtender1″ runat=”server”>
</cc1:ModalPopupExtender>
form>
</body>
</html>

.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
{
protected void Page_Load(object sender, EventArgs e)
{
ucdetail.close += new EventHandler(ucdetail_close);

}

void ucdetail_close(object sender, EventArgs e)
{
ModalPopupExtender1.Hide();
}
}
.ascx

<%@ Control Language=”C#” AutoEventWireup=”true” CodeFile=”WebUserControl.ascx.cs” Inherits=”WebUserControl” %>
UpdatePanel ID=”up1″ runat=”server” >
<ContentTemplate >

;height:100px;background-color:Maroon;”>

&nbsp;
<asp:Button ID=”Button2″ runat=”server” onclick=”Button2_Click” Text=”Close” />

<br />
<br />

TextBox ID=”TextBox1″ runat=”server”>
&nbsp;
<asp:Button ID=”Button1″ runat=”server” Text=”Button” />
</div>

</ContentTemplate>
</asp:UpdatePanel>
.ascs.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 WebUserControl : System.Web.UI.UserControl
{
public event EventHandler close;
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button2_Click(object sender, EventArgs e)
{//close
close(sender, e);

}
}

.css

.background
{
background-color:Yellow;
filter:alpha(opacity=60);
opacity:0.6;
}

file uploadng & downloading

.aspx

<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

xmlns=”http://www.w3.org/1999/xhtml“>
<head runat=”server”>
<title></title>
<style type=”text/css”>
.style1
{
width: 100%;
}
</style>
</head>
<body>
<form id=”form1″ runat=”server”>
<table>
<tr>
<td>
file
</td>
<td>
FileUpload ID=”FileUpload1″ runat=”server” />
</td>
</tr>
<tr>
<td>
&nbsp;
<td>
<asp:Button ID=”btnUpload” runat=”server” Text=”Upload”
onclick=”btnUpload_Click” />
</td>
</tr>
<tr>
<td>
&nbsp;
<td>
<br />
<br />
<asp:Button ID=”Button1″ runat=”server” onclick=”Button1_Click” Text=”Upload” />
&nbsp;
<asp:Button ID=”Button2″ runat=”server” onclick=”Button2_Click”
Text=”Downloading” />
</td>
</tr>
</table>
<div>

</div>
</form>
</body>
</html>
.cs

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader rd;
public _Default()
{
con = new SqlConnection(“initial catalog=emp;integrated security=yes”);
con.Open();
}
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnUpload_Click(object sender, EventArgs e)
{
FileUpload1.SaveAs(Server.MapPath(“fileupload/”) + FileUpload1.FileName);
con.Close();
con.Open();
cmd = new SqlCommand(“insert into filedata values(‘” + “fileupload/” + FileUpload1.FileName + “‘)”, con);
int t =cmd.ExecuteNonQuery();
if (t>0)
{
Response.Write(“<script>alert(‘file uploaded’);</script>”);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
con.Close();
con.Open();
cmd = new SqlCommand(“select * from filedata”, con);
rd = cmd.ExecuteReader();
while (rd.Read())
{
string s= rd[0] .ToString();
string[] s1= s.Split(“/”.ToCharArray());
Response.Write(“” +s1[1].ToString()+ ”  download
“);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
DirectoryInfo d = new DirectoryInfo(Server.MapPath(“fileupload/”));
FileInfo[] f =d.GetFiles();
for (int i = 0; i < f.Length; i++)
{
Response.Write(“” + “fileupload/”+f[i].ToString()+ ”  download
“);
}
}
}

/*Directory info of your system (default.cs)*/
using System;
using System.IO;
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
{
protected void Page_Load(object sender, EventArgs e)
{
string[] s = Environment.GetLogicalDrives();
for (int i = 0; i < s.Length-1; i++)
{
DropDownList1.Items.Add(s[i].ToString());
}

}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DirectoryInfo d = new DirectoryInfo(DropDownList1.SelectedItem.Text);
DirectoryInfo[] folderinfo  =d.GetDirectories();
for (int i = 0; i < folderinfo.Length-1; i++)
{
DropDownList2.Items.Add(folderinfo[i].Name.ToString());
}
}
}
/*Directory info of ur system (defalult.aspx)*/
<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

xmlns=”http://www.w3.org/1999/xhtml“>
<head runat=”server”>
<title></title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
drive name&nbsp;
DropDownList ID=”DropDownList1″ runat=”server” AutoPostBack=”True”
onselectedindexchanged=”DropDownList1_SelectedIndexChanged”>
DropDownList>

<br />
<br />
folder info&nbsp;

DropDownList ID=”DropDownList2″ runat=”server”>
</asp:DropDownList>
</div>
</form>
</body>
</html>

/*…………..updation in gridview(default.cs)………..*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader rd;
public _Default()
{
con = new SqlConnection(“initial catalog=emp;integrated security=yes”);
con.Open();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillGrid();
}
}
void fillGrid()
{
con.Close();
con.Open();
cmd = new SqlCommand(“select * from employee”,con);
GridView1.DataSource = cmd.ExecuteReader();
GridView1.DataBind();
}
protected void editRecord(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
fillGrid();
}
protected void cancelRecord(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
fillGrid();
}
protected void updateRecord(object sender, GridViewUpdateEventArgs e)
{
Label lblEmpId =GridView1.Rows[e.RowIndex].FindControl(“lblEmpId”) as Label;
TextBox txtEmpName = GridView1.Rows[e.RowIndex].FindControl(“txtEmpName”) as TextBox;
TextBox txtEmpSalary = GridView1.Rows[e.RowIndex].FindControl(“txtEmpSalary”) as TextBox;
con.Close();
con.Open();
cmd = new SqlCommand(“update employee set empName=’”+txtEmpName.Text+”‘,empSalary=”+Convert.ToDecimal(txtEmpSalary.Text)+” where empId=”+Convert.ToInt32(lblEmpId.Text)+””,con);
if (cmd.ExecuteNonQuery() > 0)
{
GridView1.EditIndex = -1;
fillGrid();
}
}
}
/*……………updation in gridview(default.aspx)………….*/
<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

xmlns=”http://www.w3.org/1999/xhtml“>
<head runat=”server”>
<title></title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
GridView ID=”GridView1″ OnRowUpdating=”updateRecord”
OnRowCancelingEdit=”cancelRecord” OnRowEditing=”editRecord”
AutoGenerateColumns=”False”  runat=”server” BackColor=”#DEBA84″
BorderColor=”#DEBA84″ BorderStyle=”None” BorderWidth=”1px” CellPadding=”3″
CellSpacing=”2″>
<RowStyle BackColor=”#FFF7E7″ ForeColor=”#8C4510″ />
<Columns>
TemplateField HeaderText=”Emp Id”>
<ItemTemplate>
<asp:Label ID=”lblEmpId” runat=”server” Text=’<%# bind(“EmpId”) %>’></asp:Label>
</ItemTemplate>
TemplateField>
TemplateField ItemStyle-Width=”110px” HeaderText=”Emp Name”>
<ItemTemplate>

</asp:Label>
</ItemTemplate>
<EditItemTemplate>

</asp:TextBox>
</EditItemTemplate>

<ItemStyle Width=”110px”>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width=”110px” HeaderText=”Emp Salary”>
<ItemTemplate>

</asp:Label>
</ItemTemplate>
<EditItemTemplate>

</asp:TextBox>
</EditItemTemplate>

<ItemStyle Width=”110px”>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width=”150px” HeaderText=”Operation”>
<ItemTemplate>
<asp:Button ID=”btnEdit” runat=”server” CommandName=”Edit” Text=”Edit” />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID=”btnUpdate” runat=”server” CommandName=”Update” Text=”Update” />
<asp:Button ID=”btnCancel” CommandName=”cancel” runat=”server” Text=”Cancel” />
</EditItemTemplate>

<ItemStyle Width=”150px”></ItemStyle>
</asp:TemplateField>

</Columns>
<FooterStyle BackColor=”#F7DFB5″ ForeColor=”#8C4510″ />
<PagerStyle ForeColor=”#8C4510″ HorizontalAlign=”Center” />
<SelectedRowStyle BackColor=”#738A9C” Font-Bold=”True” ForeColor=”White” />
<HeaderStyle BackColor=”#A55129″ Font-Bold=”True” ForeColor=”White” />
</asp:GridView>
</div>
</form>
</body>
</html>

/*…………checkall in gridview (default.cs)…………*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader rd;
public _Default()
{
con = new SqlConnection(“initial catalog=emp;integrated security=yes”);
con.Open();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillGrid();
}

}
void fillGrid()
{
con.Close();
con.Open();
cmd = new SqlCommand(“select * from employee”,con);
rd = cmd.ExecuteReader();
g1.DataSource = rd;
g1.DataBind();
}
protected void checkRows(object sender, EventArgs e)
{
CheckBox chkAll  =g1.HeaderRow.FindControl(“chkAll”) as CheckBox;
foreach (GridViewRow gr in g1.Rows)
{
CheckBox chkRow = gr.FindControl(“chkRow”) as CheckBox;
if (chkAll.Checked==true)
{
chkRow.Checked = true;
}
else
{
chkRow.Checked = false;
}
}

}

protected void deleteRecord(object sender, EventArgs e)
{
foreach (GridViewRow gr in g1.Rows)
{
CheckBox chkRow = gr.FindControl(“chkRow”) as CheckBox;
Label lblEmpId = gr.FindControl(“lblEmpId”) as Label;
if (chkRow.Checked == true)
{
con.Close();
con.Open();
cmd = new SqlCommand(“delete employee where empId=”+Convert.ToInt32(lblEmpId.Text)+””,con);
int t =cmd.ExecuteNonQuery();
if (t>0)
{
fillGrid();
}
}

}

}
}
/*………………..check all in gridview (default.aspx)……….*/
<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

xmlns=”http://www.w3.org/1999/xhtml“>
<head runat=”server”>
<title></title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:GridView AutoGenerateColumns=”false”  ID=”g1″ runat=”server” >
<Columns>
<asp:TemplateField>
<HeaderTemplate>

;”>

<div style=”float:left;”>
<asp:Button OnClick=”deleteRecord” ID=”btnDelete” runat=”server” Text=”Delete” />
</div>
<div style=”float:left;”>
CheckBox OnCheckedChanged=”checkRows” AutoPostBack=”true” ID=”chkAll” Text=”Check All” runat=”server” />
</div>
</div>
</HeaderTemplate>
<ItemTemplate>
CheckBox ID=”chkRow” runat=”server” />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Emp Id”>
<ItemTemplate>
<asp:Label ID=”lblEmpId” runat=”server” Text=’<%# bind(“EmpId”) %>’></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Emp Name”>
<ItemTemplate>

</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Emp Salary”>
<ItemTemplate>

</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>

/*……….controls………..*/
Types of control
*html controls
*server controls
*user controls
*custom controls
as we already did the html and server controls
now we will study on user controls and custom controls
User controls:-these controls are the combination of “sever and
html controls”
-> avoid redundancy of code and UI
example
/*…………default.aspx.cs……….*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WebUserControl : System.Web.UI.UserControl
{
SqlConnection con;
SqlDataAdapter adap;
DataSet ds;
public WebUserControl()
{
con = new SqlConnection(“initial catalog=emp;integrated security=yes”);
ds = new DataSet();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillCountry();
}

}
void fillCountry()
{
adap = new SqlDataAdapter(“select * from country”,con);
adap.Fill(ds,”country”);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = “CountryName”;
DropDownList1.DataValueField = “pkCountryId”;
DropDownList1.DataBind();

}
}
/*………………..web contol.acsx……….*/
<%@ Control Language=”C#” AutoEventWireup=”true” CodeFile=”WebUserControl.ascx.cs” Inherits=”WebUserControl” %>
<style type=”text/css”>
.style1
{
width: 100%;
}
</style>
<table>
<tr>
<td>
Country Name
</td>
<td>
<asp:DropDownList ID=”DropDownList1″ runat=”server”>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
State Name</td>
<td>
<asp:DropDownList ID=”DropDownList2″ runat=”server”>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
City Name</td>
<td>
<asp:DropDownList ID=”DropDownList3″ runat=”server”>
</asp:DropDownList>
<br />
<br />
<br />
<br />
<br />
</td>
</tr>
<tr>
<td>
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
</table>
/*……….how to access the controls of user control in aspx page………*/
first go to default page and do the following code on button’s click event
/*………………….Default.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
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox txt =city1.FindControl(“TextBox1″) as TextBox;
Response.Write(“<script>alert(‘”+txt.Text+”‘)</script>”);
}
}
/*………………………Default.aspx………………….*/
<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
Src=”~/WebUserControl.ascx” TagPrefix=”uc” TagName=”city” %>
DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

xmlns=”http://www.w3.org/1999/xhtml“>
<head runat=”server”>
<title></title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<uc:city ID=”city1″ runat=”server” />
</div>
<asp:Button ID=”Button1″ runat=”server” onclick=”Button1_Click” Text=”Button” />
</form>
</body>
</html>
/*………………….default2.aspx……………………….*/
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default2.aspx.cs” Inherits=”Default2″ %>
Src=”~/WebUserControl.ascx” TagPrefix=”uc1″ TagName=”search” %>
DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

xmlns=”http://www.w3.org/1999/xhtml“>
<head runat=”server”>
<title></title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<uc1:search ID=”uc2″ runat=”server” />
</div>
</form>
</body>
</html>

The default2.aspx page don’t contain cs page it is linked with the coding of above cs page

/*……….how to convert html control to server control…………*/
/*……….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
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
btnGrid.Visible = false;
divGrid.Visible = false;
}

}
protected void btnDesc_Click(object sender, EventArgs e)
{
btnGrid.Visible = true;
divDesc.Visible = true;
btnDesc.Visible = false;
divGrid.Visible = false;

}
protected void btnGrid_Click(object sender, EventArgs e)
{
btnGrid.Visible = false;
divDesc.Visible = false;
btnDesc.Visible = true;
divGrid.Visible = true;
}
}
/*………….default.aspx……….*/
<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!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”>
<asp:Button ID=”btnDesc” runat=”server” Text=”Description”
onclick=”btnDesc_Click” />
<asp:Button ID=”btnGrid” runat=”server” Text=”Grid” onclick=”btnGrid_Click” />
<br />
<div id=”divDesc” runat=”server” >
description

<br />
<br />

</div>

<div id=”divGrid” runat=”server” >
grid
<br />
<br />
</div>
</form>
</body>
</html>

/*.............................how to create login page(default.aspx.cs)..................................*/

using System;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Data;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

public

partialclass_Default : System.Web.UI.Page

{

SqlConnection con;

SqlCommand cmd;

SqlDataReader rd;

public_Default()

{

con = newSqlConnection("initial catalog=neha;integrated security=yes");

con.Open();

}

protectedvoid Page_Load(object sender, EventArgs e)

{

}

protectedvoid Button1_Click(object sender, EventArgs e)

{

con.Close();

con.Open();

cmd = newSqlCommand("select usertype from login where username='"+TextBox1.Text+"' and passwrd='"+TextBox2.Text+"' ",con);

rd = cmd.ExecuteReader();

bool b = rd.Read();

if (b==true)

{

if (rd["usertype"].ToString()=="admin")

{

Response.Redirect("admin.aspx");

}

elseif (rd["usertype"].ToString()=="user")

{

Response.Redirect("user.aspx");

}

}

else

{

Response.Write("<script>alert('un & pwd not valid')</script>");

}

}

}

/*..........................................Default.aspx.................................*/

<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

<styletype="text/css">.style1

{

width: 100%;

}

</style>

</head>

<body>

<formid="form1"runat="server">

<div>

<tableclass="style1">

<tr>

<td>

User Name

</td>

<td>

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>

</td>

</tr>

<tr>

<td>

Password

</td>

<td>

<asp:TextBoxID="TextBox2"runat="server"></asp:TextBox>

</td>

</tr>

<tr>

<td>

<asp:ButtonID="Button1"runat="server"onclick="Button1_Click"Text="Login"/>

</td>

<td>

&nbsp;</td>

</tr>

</table>

</div>

</form>

</body>

</html>

/*………..web controls………*/

These are those controls which are common
to all we register those control to a web page and call whenever we need them
Here we study:-
->textbox on user control
->button on user control

/*……..textbox on user control(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
{
protected void Page_Load(object sender, EventArgs e)
{
b1.buttonClick += new EventHandler(b1_buttonClick);
}

void b1_buttonClick(object sender, EventArgs e)
{
Response.Write(“<script>alert(‘”+TextBox1.Text+”‘)</script>”);
}
protected void custombutton1_Click(object sender, EventArgs e)
{
Response.Write(“<script>alert(‘” + TextBox1.Text + “‘)</script>”);

}
}

/*………………textbox on user control(default.aspx)………..*/
<!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>
<uc:bubble ID=”b1″ runat=”server” />
<br />
<br />
<br />
<cc1:custombutton  Text=”show” ID=”custombutton1″ runat=”server”
onclick=”custombutton1_Click” />
<br />
<br />
<br />
<br />
<br />
<br />
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
</div>
</form>
</body>
</html>

/*………..button on user control(web control.ascx.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 WebUserControl : System.Web.UI.UserControl
{
public event EventHandler buttonClick;
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
buttonClick(sender, e);
}
}

/*…………………..button on user control(webcontrol.ascx)………….*/
<%@ Control Language=”C#” AutoEventWireup=”true” CodeFile=”WebUserControl.ascx.cs” Inherits=”WebUserControl” %>

<asp:Button ID=”Button1″ runat=”server” Text=”bubble” onclick=”Button1_Click” />
/*
The button on user control is called as is
called as bubble event handler
*/

/*……………….custom controls………*/
The main drwaback of user controls are:-
1->It is n’t pre complied
2->Just only used once
toh for avoiding these situation a control is created
this control is called as “custom control”
Custom control:-
1->Pre complied
2->simillarly same as dll
3->once created used many times

/*we generally create it in class library same as dll is created*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace custombatchc
{
public class custombutton:Button

{
public custombutton()
{
this.BackColor = System.Drawing.Color.Brown;
}
}
}

// In this program we had added the reference of:-
System.Data
System.Data.DatasetExtensions
System.Drawing
System.Web
System.Xml
System.Xml.Linq
//

/*………..how to show and save image in datalist………*/
/*……….Default.aspx.cs……….*/using System;
using System.Data.SqlClient;
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
{
SqlConnection con;
SqlCommand cmd;
public _Default()
{
con = new SqlConnection(“initial catalog=emp;integrated security=yes”);
con.Open();
}
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnAdd_Click(object sender, EventArgs e)
{
string filepath=Server.MapPath(“image/”)+FileUpload1.FileName;
FileUpload1.SaveAs(filepath);

cmd = new SqlCommand(“insert into productinfo values(‘”+filepath+”‘,’”+txtProdName.Text+”‘,”+Convert.ToDecimal(txtProdPrice.Text)+”)”,con);
int t=cmd.ExecuteNonQuery();
if (t>0)
{
Response.Redirect(“Default2.aspx”);
}
}
}
/*……………Default.aspx………….*/
<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!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>
<style type=”text/css”>
.style1
{
width: 100%;
}
</style>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>

<table>
<tr>
<td>
Product Image</td>
<td>
<asp:FileUpload ID=”FileUpload1″ runat=”server” />
</td>
</tr>
<tr>
<td>
Product Name</td>
<td>
<asp:TextBox ID=”txtProdName” runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td>
Product Pice</td>
<td>
<asp:TextBox ID=”txtProdPrice” runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID=”btnAdd” runat=”server” onclick=”btnAdd_Click”
Text=”Add image” />
</td>
</tr>
</table>

</div>
</form>
</body>
</html>
/*………………………Default2.aspx.cs………….*/
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader rd;
public Default2()
{
con = new SqlConnection(“initial catalog=emp;integrated security=yes”);
con.Open();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
cmd = new SqlCommand(“select * from productinfo”,con);
DataList1.DataSource = cmd.ExecuteReader();
DataList1.DataBind();
}
}
}
/*……………………..Default2.aspx…………….*/
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default2.aspx.cs” Inherits=”Default2″ %>

<!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:DataList RepeatColumns=”3″ ID=”DataList1″ runat=”server”>
<ItemTemplate>
<table>
<tr>
<td>
<asp:Image Width=”100px” Height=”100px” ImageUrl=’<%# bind(“ProductImagePath”) %>’ ID=”Image1″ runat=”server” />
</td>
</tr>
<tr>
<td>
<asp:Label ID=”Label1″ runat=”server” Text=’<%# bind(“ProductName”) %>’></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID=”Label2″ runat=”server” Text=’<%# bind(“ProductPrice”) %>’></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>

/*…………Static Object……….*/
/*……..defalut.aspx.cs…..*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = Application["ds"];
GridView1.DataBind();
Response.Write(Session["count"].ToString());

}
}
/*…………..Default.aspx…….*/
<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!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:GridView ID=”GridView1″ runat=”server”>
</asp:GridView>
</div>
</form>
</body>
</html>

/*………………………………………….  Insertion  into Gridview………………………………..*/

/*……………………………………….Default  .aspx………………………………………….*/
<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!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>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:GridView ShowFooter=”True” ID=”GridView1″ AutoGenerateColumns=”False”
runat=”server”>
<Columns>
<asp:TemplateField HeaderText=”Emp Name”>
<ItemTemplate>
<asp:Label ID=”lblEmpName” runat=”server” Text=’<%# bind(“empname”) %>’  ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID=”txtEmpName” runat=”server”></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Emp Address”>
<ItemTemplate>
<asp:Label ID=”lblEmpAddress” runat=”server” Text=’<%# bind(“empAddress”) %>’  ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID=”txtEmpAddress” runat=”server”></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Emp Salary”>
<ItemTemplate>
<asp:Label ID=”lblEmpSalary” runat=”server” Text=’<%# bind(“empsalary”) %>’  ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID=”txtEmpSalary” runat=”server”></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Operation”>
<FooterTemplate>
<asp:Button OnClick=”AddRecord” ID=”btnAdd” runat=”server” Text=”Add” />
</FooterTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
/*…………………………………….. Default .cs…………………………………*/

using System;

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

public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader rd;
public _Default()
{
con = new SqlConnection(“initial catalog=emp;integrated security=yes”);
con.Open();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillGrid();
}
}
public void fillGrid()
{
con.Close();
con.Open();
cmd = new SqlCommand(“select * from employee”,con);
rd =cmd.ExecuteReader();
GridView1.DataSource = rd;
GridView1.DataBind();
}
protected void AddRecord(object sender, EventArgs e)
{
TextBox txtEmpName =GridView1.FooterRow.FindControl(“txtEmpName”) as TextBox;
TextBox txtEmpAddress = GridView1.FooterRow.FindControl(“txtEmpAddress”) as TextBox;
TextBox txtEmpSalary = GridView1.FooterRow.FindControl(“txtEmpSalary”) as TextBox;
con.Close();
con.Open();
cmd = new SqlCommand(“insert into employee values(‘”+txtEmpName.Text+”‘,’”+txtEmpAddress.Text+”‘,’”+Convert.ToInt32(txtEmpSalary.Text)+”‘)”,con);
int t=cmd.ExecuteNonQuery();
if (t>0)
{
fillGrid();
}
}

}

/*……………..how to make connectivity between two pages with the help of javascript……………..*/
/*…………..default.aspx……………….*/
Page Language=”VB” AutoEventWireup=”false” CodeFile=”Default.aspx.vb” Inherits=”_Default” %>

<!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>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
</p>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID=”Button1″ OnClientClick=”return window.open(‘popup.aspx’);” runat=”server” Text=”popup” />
&nbsp;</p>
<div>

</div>
</form>
</body>
</html>
/*………………popup.aspx………………*/

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”popup.aspx.cs” Inherits=”popup” %>

<!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>Untitled Page</title>
<script language=”javascript” >
function fillData() {
window.opener.document.getElementById(‘TextBox1′).value = document.getElementById(‘TextBox1′).value;
return false;

}

</script>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>

<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
<br />
<br />
&nbsp;
<asp:Button ID=”Button1″ OnClientClick=”return fillData();” runat=”server” Text=”Send Data” />

</div>
</form>
</body>
</html>

/*……………….paging…………….*/
/*……………….default.aspx.cs………..*/
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader rd;
public _Default()
{
con = new SqlConnection(“initial catalog=abhi;integrated security=yes”);
con.Open();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillGrid();
}
}
void fillGrid()
{
cmd = new SqlCommand(“select * from employee”,con);
rd = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(rd);
GridView1.DataSource=dt;
GridView1.DataBind();
}

protected void nextpage(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
fillGrid();
}
}
/*……………………….default.aspx………………*/
<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!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>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:GridView PageSize=”5″ AllowPaging=”true” PagerSettings-Mode=”Numeric”
AllowSorting=”true”  ID=”GridView1″ runat=”server”
onpageindexchanging=”nextpage”>
</asp:GridView>
</div>
</form>
</body>
</html>

/*……………………hyperlinkig…………….*/
/*………………….default.aspx.cs……………*/
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader rd;
public _Default()
{
con = new SqlConnection(“initial catalog=abhi;integrated security=yes”);
con.Open();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillGrid();
}
}
void fillGrid()
{
cmd = new SqlCommand(“select * from employee”,con);
rd = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(rd);
GridView1.DataSource=dt;
GridView1.DataBind();
}

protected void nextpage(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
fillGrid();
}
}
/*……………………..default.aspx……………..*/
<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!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>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:GridView AutoGenerateColumns=”false” PageSize=”5″ AllowPaging=”true” PagerSettings-Mode=”Numeric”
AllowSorting=”true”  ID=”GridView1″ runat=”server”
onpageindexchanging=”nextpage”>
<Columns>
<asp:HyperLinkField HeaderText=”Emp Id” DataTextField=”EmpId” DataNavigateUrlFields=”EmpId” DataNavigateUrlFormatString=”detail.aspx?EmpId={0}” />
<asp:TemplateField HeaderText=”Emp Name” >
<ItemTemplate>
<asp:Label ID=”Label1″ runat=”server” Text=’<%# bind(“EmpName”) %>’ ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
/*…………………….detail.cs…………………*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class detail : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader rd;
public detail()
{
con = new SqlConnection(“initial catalog=abhi;integrated security=yes”);
con.Open();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillGrid();
}
}
void fillGrid()
{
cmd = new SqlCommand(“select * from empdetail where EmpId=”+Convert.ToInt32(Request.QueryString["EmpId"].ToString())+””,con);
rd = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(rd);
GridView1.DataSource=dt;
GridView1.DataBind();
}

protected void nextpage(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
fillGrid();
}
}

/*…………………………detail.aspx……………….*/

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”detail.aspx.cs” Inherits=”detail” %>

<!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>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:GridView ID=”GridView1″ runat=”server”>
</asp:GridView>
</div>
</form>
</body>
</html>

XMLFile.xml

<?xml version=”1.0″ standalone=”yes”?>
<NewDataSet>
<EmpDetail>
<EmpId>101</EmpId>
<EmpSalary>10000</EmpSalary>
</EmpDetail>
<EmpDetail>
<EmpId>102</EmpId>
<EmpSalary>2000</EmpSalary>
</EmpDetail>
<EmpDetail>
<EmpId>103</EmpId>
<EmpSalary>3000</EmpSalary>
</EmpDetail>
<EmpDetail>
<EmpId>104</EmpId>
<EmpSalary>12233</EmpSalary>
</EmpDetail>
<EmpDetail>
<EmpId>104</EmpId>
<EmpSalary>1000000</EmpSalary>
</EmpDetail>
<EmpDetail>
<EmpId>107</EmpId>
<EmpSalary>23</EmpSalary>
</EmpDetail>
<EmpDetail>
<EmpId>201</EmpId>
<EmpSalary>32</EmpSalary>
</EmpDetail>
</NewDataSet>

Default.aspx

=========================

<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<%@ Register assembly=”System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ namespace=”System.Web.UI.DataVisualization.Charting” tagprefix=”asp” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;

<html

xmlns=”http://www.w3.org/1999/xhtml“>
<head runat=”server”>
<title>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>

<asp:Button ID=”btnCreateXml” runat=”server” Text=”Create XML”
onclick=”btnCreateXml_Click” />
&nbsp;&nbsp;
<asp:Button ID=”btnShowInGrid” runat=”server” Text=”Show In Grid”
onclick=”btnShowInGrid_Click” />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID=”btnGraph” runat=”server” Text=”Graph”
onclick=”btnGraph_Click” />
<br />
<br />
&nbsp;<br />
<br />
<asp:GridView ShowFooter=True AutoGenerateColumns=”False” ID=”GridView1″
runat=”server” BackColor=”White” BorderColor=”#E7E7FF” BorderStyle=”None”
BorderWidth=”1px” CellPadding=”3″ GridLines=”Horizontal”>
<RowStyle BackColor=”#E7E7FF” ForeColor=”#4A3C8C” />
<Columns>
<asp:TemplateField HeaderText=”Emp Id”>
<ItemTemplate>
<asp:Label ID=”lblEmpId” runat=”server” Text=’<%# bind(“EmpId”) %>’  ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID=”txtEmpId” runat=”server”></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Emp Salary”>
<ItemTemplate>
<asp:Label ID=”lblEmpSalary” runat=”server” Text=’<%# bind(“EmpSalary”) %>’  ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID=”txtEmpSalary” runat=”server”></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Opeartion”>
<FooterTemplate>
<asp:Button ID=”btnAdd” runat=”server” OnClick=”addrecord” Text=”Add Record” />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor=”#B5C7DE” ForeColor=”#4A3C8C” />
<PagerStyle BackColor=”#E7E7FF” ForeColor=”#4A3C8C” HorizontalAlign=”Right” />
<SelectedRowStyle BackColor=”#738A9C” Font-Bold=”True” ForeColor=”#F7F7F7″ />
<HeaderStyle BackColor=”#4A3C8C” Font-Bold=”True” ForeColor=”#F7F7F7″ />
<AlternatingRowStyle BackColor=”#F7F7F7″ />
</asp:GridView>

<asp:Chart ID=”Chart1″ runat=”server”>
<series>
<asp:Series Name=”Series1″>
</asp:Series>
</series>
<chartareas>
<asp:ChartArea Name=”ChartArea1″>
</asp:ChartArea>
</chartareas>
</asp:Chart>

</div>
</form>
</body>
</html>

Default.aspx.cs

===========================

using System;
using System.Configuration;
using System.Data;
using System.Web.UI.DataVisualization;
using System.Web.UI.DataVisualization.Charting;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}

}
protected void btnCreateXml_Click(object sender, EventArgs e)
{
XmlTextWriter xt = new XmlTextWriter(Server.MapPath(“XMLFile.xml”), null);
xt.WriteStartDocument();
xt.WriteStartElement(“EmpDetail”);
xt.WriteElementString(“EmpId”, “101″);
xt.WriteElementString(“EmpSalary”, “10000″);
xt.WriteEndElement();
xt.WriteEndDocument();
xt.Close();

}
protected void btnShowInGrid_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(“XMLFile.xml”));
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void addrecord(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(“XMLFile.xml”));
TextBox txtEmpId=GridView1.FooterRow.FindControl(“txtEmpId”) as TextBox;
TextBox txtEmpSalary = GridView1.FooterRow.FindControl(“txtEmpSalary”) as TextBox;
DataRow dr =ds.Tables[0].NewRow();
dr["EmpId"] = txtEmpId.Text;
dr["EmpSalary"] = txtEmpSalary.Text;
ds.Tables[0].Rows.Add(dr);
ds.WriteXml(Server.MapPath(“XMLFile.xml”));
btnShowInGrid_Click(sender, e);
}
protected void btnGraph_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(“XMLFile.xml”));
Chart1.Series["Series1"].ChartType = SeriesChartType.Line;
Chart1.Series["Series1"].Points.DataBindXY(ds.Tables[0].CreateDataReader(), “EmpId”, ds.Tables[0].CreateDataReader(), “EmpSalary”);
Chart1.Width = 700;
}
}

 

 

batch B1 (2012) month november 2011(new batch)

.cs

using

System;

using

System.Data;

using

System.Data.SqlClient;

public

class

abc

 

{

SqlConnection con;SqlCommand cmd;SqlDataReader rd;public abc()

{

con =

newSqlConnection(“initial catalog=abhi;integrated security=yes;”);

 

}

publicvoid show()

{

con.Open();

cmd =

newSqlCommand(“select * from employee”,con);

rd =cmd.ExecuteReader();

//rd.Read();

 

DataTable dt = newDataTable();

dt.Load(rd);

DataTableReader rd1 =dt.CreateDataReader();while (rd1.Read())

{

Console.WriteLine(rd1["EmpId"].ToString() + ” “ + rd1["EmpName"].ToString() + ” “ + rd1["EmpSalary"].ToString());

}

con.Close();

}

publicstaticvoid Main()

{

abc obj = newabc();

obj.show();

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

Archives

Follow

Get every new post delivered to your Inbox.

Join 35 other followers

%d bloggers like this: