0% found this document useful (0 votes)
4 views

DOT NET

The document outlines the creation of various ASP.NET applications that utilize HTML server controls and data access techniques. It includes examples of forms for job seekers, data retrieval and display in tables, and the use of data grid and data list controls to interact with SQL Server databases. Each example demonstrates different functionalities such as form submission, data binding, and CRUD operations on employee records.

Uploaded by

sribrowsing31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

DOT NET

The document outlines the creation of various ASP.NET applications that utilize HTML server controls and data access techniques. It includes examples of forms for job seekers, data retrieval and display in tables, and the use of data grid and data list controls to interact with SQL Server databases. Each example demonstrates different functionalities such as form submission, data binding, and CRUD operations on employee records.

Uploaded by

sribrowsing31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1) DESIGN ASP.

NET WEB FROM USING HTML SERVER CONTROLS TO ENTER JOB SEEKERS DETAIL

INPUT:

<html>
<body>
@{
if (IsPost)
{
string companyname = Request["CompanyName"];
string contactname = Request["ContactName"];
<p>You entered: <br>
Company Name: @companyname <br>
Contact Name: @contactname </p>
}
else
{
<form method="post" action="">
Company Name:<br>
<input type="text" name="CompanyName" value=""><br>
Contact Name:<br><br>
<input type="text" name="ContactName" value=""><br><br>
<input type="submit" value="Submit" class="submit">
</form>
}
}
</body>
</html>

OUTPUT:
2) Write An Asp.Net Application To Retrive Form Date And Display It Hte Client Browser In A Table
Format

INPUT:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFormAdoNet.aspx.cs"


Inherits="ado.netWebFormExample.WebFormAdoNet" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 100px;
}
.auto-style3 {
width: 95px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:Label runat="server" Text="User Name" ID="usernamelabelId"></asp:Label></td>
<td>
<asp:TextBox ID="UsernameId" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label runat="server" Text="Email ID"></asp:Label></td>
<td>
<asp:TextBox ID="EmailId" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label runat="server" Text="Contact"></asp:Label></td>
<td>
<asp:TextBox ID="ContactId" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td class="auto-style2"></td>
<td>
<asp:Button ID="ButtonId" runat="server" Text="Submit" OnClick="ButtonId_Click" /></td>
</tr>
</table>
</div>
<div>
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
<table class="auto-style1">
<tr>
<td class="auto-style3">
<asp:Label ID="Label2" runat="server"></asp:Label></td>
<td>
<asp:Label ID="Label5" runat="server"></asp:Label></td>
</tr>
<tr>
<td class="auto-style3">
<asp:Label ID="Label3" runat="server"></asp:Label></td>
<td>
<asp:Label ID="Label6" runat="server"></asp:Label></td>
</tr>
<tr>
<td class="auto-style3">
<asp:Label ID="Label4" runat="server"></asp:Label></td>
<td>
<asp:Label ID="Label7" runat="server"></asp:Label></td>
</tr>
</table>
</body>
</html>

OUTPUT:
3) Create an application using Date grid control to access information’s from table in SQL Server.

INPUT:
using System.Data.Entity.Core.Objects;
using System.Linq;
using System.Windows;

namespace DataGridSQLExample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
AdventureWorksLT2008Entities dataEntities = new AdventureWorksLT2008Entities();

public MainWindow()
{
InitializeComponent();
}

private void Window_Loaded(object sender, RoutedEventArgs e)


{
var query =
from product in dataEntities.Products
where product.Color == "Red"
orderby product.ListPrice
select new { product.Name, product.Color, CategoryName = product.ProductCategory.Name,
product.ListPrice };

dataGrid1.ItemsSource = query.ToList();
}
}
}

OUTPUT:

4) Create an application using Data grid control to access information’s from table in SQL server.
INPUT:
private void btnRefresh_Click(object sender, EventArgs e)
{
//set the connection string
string connString = @"Server =.\SQL2K17; Database = SampleDB; Trusted_Connection =
True;"try
{
//sql connection object
using (SqlConnection conn = new SqlConnection(connString))
{
//retrieve the SQL Server instance version
string query = @"SELECT e.id,
e.code,
e.firstName,
e.lastName,
l.code AS locationCode,
l.descr AS locationDescr
FROM dbo.employees e
INNER JOIN dbo.location l
ON l.id = e.locationID;"//define the SqlCommand object
SqlCommand cmd = new SqlCommand(query, conn);

//Set the SqlDataAdapter object


SqlDataAdapter dAdapter = new SqlDataAdapter(cmd);
//define dataset
DataSet ds = new DataSet();
//fill dataset with query results
dAdapter.Fill(ds);
//set DataGridView control to read-only
grdData.ReadOnly = true//set the DataGridView control's data source/data
table
grdData.DataSource = ds.Tables[0];

//close connection
conn.Close();
}
}
catch (Exception ex)
{
//display error message
MessageBox.Show("Exception: " + ex.Message);
}
}

OUTPUT:
5) Create an application using Data list control to access information’s from table in SQL Server and display the
result in neat format.

INPUT:

1. using System;
2. using System.Collections.Generic;
3. using System.Linq;
4. using System.Web;
5. using System.Web.UI;
6. using System.Web.UI.WebControls;
7. using System.Configuration;
8. using System.Data;
9. using System.Data.SqlClient;
10.
11. public partial class UI_DataList : System.Web.UI.Page
12. {
13. string connection = ConfigurationManager.ConnectionStrings["connstring"].C
onnectionString;
14. protected void Page_Load(object sender, EventArgs e)
15. {
16. if (!IsPostBack)
17. {
18. GetEmpDataList();
19. }
20. }
21. protected void btnSave_Click(object sender, EventArgs e)
22. {
23. using (SqlConnection con = new SqlConnection(connection))
24. {
25. using (SqlCommand cmd = new SqlCommand("sp_InsertEmployeeData",
con))
26. {
27. cmd.CommandType = CommandType.StoredProcedure;
28.
29. cmd.Parameters.AddWithValue("@EmpName", SqlDbType.VarChar).V
alue = txtName.Text.Trim();
30. cmd.Parameters.AddWithValue("@Contact", SqlDbType.NChar).Value
= txtContact.Text.Trim();
31. cmd.Parameters.AddWithValue("@EmailId", SqlDbType.NVarChar).Val
ue = txtEmail.Text.Trim();
32.
33. con.Open();
34. cmd.ExecuteNonQuery();
35. con.Close();
36.
37. Clear();
38. Response.Write("<script type=\"text/javascript\">alert('Record Insert
ed Successfully');</script>");
39. GetEmpDataList();
40. }
41. }
42. }
43. void Clear()
44. {
45. txtName.Text = String.Empty;
46. txtContact.Text = String.Empty;
47. txtEmail.Text = String.Empty;
48. }
49. private void GetEmpDataList()
50. {
51. using (SqlConnection con = new SqlConnection(connection))
52. {
53. SqlDataAdapter sd = new SqlDataAdapter("sp_FillData", con);
54. sd.SelectCommand.CommandType = CommandType.StoredProcedure;
55. DataTable dt = new DataTable();
56.
57. sd.Fill(dt);
58.
59. if (dt.Rows.Count > 0)
60. {
61. DataListEmp.DataSource = dt;
62. DataListEmp.DataBind();
63. }
64. }
65. }
66. protected void DataListEmp_DeleteCommand(object source, DataListComman
dEventArgs e)
67. {
68. int EmpID = Convert.ToInt32(DataListEmp.DataKeys[e.Item.ItemIndex].ToSt
ring());
69.
70. using (SqlConnection con = new SqlConnection(connection))
71. {
72. using (SqlCommand cmd = new SqlCommand("sp_DeleteEmployeeData",
con))
73. {
74. cmd.CommandType = CommandType.StoredProcedure;
75. cmd.Parameters.AddWithValue("@EmpID",EmpID);
76.
77. con.Open();
78. cmd.ExecuteNonQuery();
79. con.Close();
80.
81. Response.Write("<script type=\"text/javascript\">alert('Record Delete
d Successfully');</script>");
82. GetEmpDataList();
83. }
84. }
85. }
86. protected void DataListEmp_EditCommand(object source, DataListCommandE
ventArgs e)
87. {
88. DataListEmp.EditItemIndex = e.Item.ItemIndex;
89. GetEmpDataList();
90. }
91. protected void DataListEmp_CancelCommand(object source, DataListComma
ndEventArgs e)
92. {
93. DataListEmp.EditItemIndex = -1;
94. GetEmpDataList();
95. }
96. protected void DataListEmp_UpdateCommand(object source, DataListComma
ndEventArgs e)
97. {
98. int EmpID = Convert.ToInt32(DataListEmp.DataKeys[e.Item.ItemIndex].ToS
tring());
99.
100. TextBox txtName = (TextBox)e.Item.FindControl("txtName");
101. TextBox txtContact = (TextBox)e.Item.FindControl("txtContact");
102. TextBox txtEmail = (TextBox)e.Item.FindControl("txtEmail");
103.
104. using (SqlConnection con = new SqlConnection(connection))
105. {
106. using (SqlCommand cmd = new SqlCommand("sp_UpdateEmployeeData
", con))
107. {
108. cmd.CommandType = CommandType.StoredProcedure;
109.
110. cmd.Parameters.AddWithValue("@EmpID", EmpID);
111. cmd.Parameters.AddWithValue("@EmpName", SqlDbType.VarChar).V
alue = txtName.Text.Trim();
112. cmd.Parameters.AddWithValue("@Contact", SqlDbType.NChar).Value
= txtContact.Text.Trim();
113. cmd.Parameters.AddWithValue("@EmailId", SqlDbType.NVarChar).Val
ue = txtEmail.Text.Trim();
114.
115. con.Open();
116. cmd.ExecuteNonQuery();
117. con.Close();
118.
119. Clear();
120. Response.Write("<script type=\"text/javascript\">alert('Record Updat
e Successfully');</script>");
121. DataListEmp.EditItemIndex = -1;
122. GetEmpDataList();
123. }
124. }
125. }
126. }

OUTPUT:

You might also like