You are on page 1of 17

XML EMAIL SENDING

using System.Xml;

namespace XML_Email_Sending
{
public partial class EmployeeForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void txtSubmit_Click(object sender, EventArgs e)


{
XmlTextWriter writer = new XmlTextWriter(Server.MapPath(@"~\Files\Application.xml"),
System.Text.Encoding.UTF8);
writer.WriteStartDocument(false);
writer.Formatting = Formatting.Indented;
writer.Indentation = 2;
writer.WriteStartElement("Applications");
CreateNode(txtAppNo.Text, txtFirstName.Text + ' ' + txtLastName.Text,
ddlDesignation.SelectedValue.ToString(), txtExperience.Text, txtEducation.Text, txtContact.Text, writer);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
MailAddress From = new MailAddress(txtEmail.Text);
MailAddress To = new MailAddress("vpassignments.biit@gmail.com");
MailMessage message = new MailMessage(From.ToString(), To.ToString(), "Employee
Application", "");
Attachment att = new Attachment(Server.MapPath(@"~\Files\Application.xml"));
message.Attachments.Add(att);
SmtpClient smtp = new SmtpClient("smtp.gmail.com",587);
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential(txtEmail.Text, txtPassword.Text);
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Send(message);
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
}

private void CreateNode(string appNo, string name, string Desig,string exp,string edu,string contact,
XmlTextWriter writer)
{
writer.WriteStartElement("Employee");
writer.WriteStartElement("AppNo");
writer.WriteString(appNo);
writer.WriteEndElement();
writer.WriteStartElement("Name");
writer.WriteString(name);
writer.WriteEndElement();
writer.WriteStartElement("Education");
writer.WriteString(edu);
writer.WriteEndElement();
writer.WriteStartElement("Designation");
writer.WriteString(Desig);
writer.WriteEndElement();
writer.WriteStartElement("Experience");
writer.WriteString(exp);
writer.WriteEndElement();
writer.WriteStartElement("Contact");
writer.WriteString(contact);
writer.WriteEndElement();
writer.WriteEndElement();
}
}
}

AJAX TIMER CONTROL


<body>
<form id="form1" runat="server">
<center>
<br />
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="1000">
</asp:Timer>
</div>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text=" Time " Font-Bold="True" Font-Size="XX-Large"
CssClass="auto-style1"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</center>
</form>
</body>

namespace vii_AjaxTimerControl
{
public partial class Time : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

Label1.Text = "Time is: " +


DateTime.Now.ToLongTimeString();
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = "Time is: " +
DateTime.Now.ToLongTimeString();
}

}
}

OLX post

protected void ButtonPostAd_Click(object sender, EventArgs e)


{
try
{
String imagePath1 = Server.MapPath(@"~\Images\") + image1Upload.FileName;
String imagePath2 = Server.MapPath(@"~\Images\") + image2Upload.FileName;
String imagePath3 = Server.MapPath(@"~\Images\") + image3Upload.FileName;
SqlConnection con = new SqlConnection(@"Data Source=Fahad-PC;Initial Catalog=test;Integrated
Security=True;");
SqlCommand cmd = new SqlCommand("Insert into PostAd Values ('" +
DropDownListCategory.SelectedValue.ToString() + "','" + textBoxItem.Text + "','" +
DropDownListCity.SelectedValue.ToString() + "','" + textBoxContact.Text + "','" + textBoxPrice.Text + "','" +
textBoxModel.Text + "','" + image1Upload.FileName + "','" + image2Upload.FileName + "','" +
image3Upload.FileName + "')", con);
image1Upload.PostedFile.SaveAs(imagePath1);
image2Upload.PostedFile.SaveAs(imagePath2);
image3Upload.PostedFile.SaveAs(imagePath3);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
LabelStatus.Text = "Ad Posted Successfully!";
}
catch (Exception ex)
{
LabelStatus.Text = ex.Message;
}
}
namespace Olx
{
public partial class SearchAd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
BindData();
FillDropDownCategory();
FillDropDownCity();
}
}

private void BindData()


{
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(@"Data Source=Fahad-PC;Initial Catalog=test;Integrated
Security=True;");
SqlDataAdapter sda = new SqlDataAdapter("Select * from PostAd ", con);
sda.Fill(dt);
sda.Dispose();
DataList1.DataSource = dt;
DataList1.DataBind();
}
private void FillDropDownCategory()
{
SqlConnection con = new SqlConnection(@"Data Source=Fahad-PC;Initial Catalog=test;Integrated
Security=True;");
SqlDataAdapter sda = new SqlDataAdapter("Select distinct Category from PostAd", con);
DataTable dt = new DataTable();
sda.Fill(dt);
DropDownListCategory.DataSource = dt;
DropDownListCategory.DataValueField = DropDownListCategory.DataTextField = "Category";
DropDownListCategory.DataBind();
}

private void FillDropDownCity()


{
SqlConnection con = new SqlConnection(@"Data Source=Fahad-PC;Initial Catalog=test;Integrated
Security=True;");
SqlDataAdapter sda = new SqlDataAdapter("Select distinct City from PostAd", con);
DataTable dt = new DataTable();
sda.Fill(dt);
DropDownListCity.DataSource = dt;
DropDownListCity.DataTextField = DropDownListCity.DataValueField = "City";
DropDownListCity.DataBind();
}
protected void ButtonSearch_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(@"Data Source=Fahad-PC;Initial Catalog=test;Integrated
Security=True;");
SqlDataAdapter sda = new SqlDataAdapter(String.Format("Select * from PostAd where City = '{0}' AND
Category = '{1}'", DropDownListCity.SelectedItem.Value, DropDownListCategory.SelectedItem.Value), con);
sda.Fill(dt);
sda.Dispose();
DataList1.DataSource = dt;
DataList1.DataBind();
}

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)


{
if(e.CommandName=="Clicked")
{
LabelCategory.Text = e.CommandArgument.ToString();
}
}
}
}

GOOGLE MAP

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC6v5-
2uaq_wusHDktM9ILcqIrlPtnZgEk&sensor=false">
</script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?">
</script>
<script type="text/javascript">
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success);
} else {
alert("Geo Location is not supported on your current browser!");
}
function success(position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
var city = position.coords.locality;
document.getElementById('<%=txtLat.ClientID %>').value = lat;
document.getElementById('<%=txtLong.ClientID %>').value = long;
}
</script>

<body >
<form id="form1" runat="server">
<div>
<center>
<asp:Label runat="server" Text="Employee Sign Up" Font-Size="XX-Large"></asp:Label>
<br />
<table style="width:30%">
<tr>
<td>
<asp:Label Text="First Name" Font-Size="Large" runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtFirstName" Font-Size="Large" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label Text="Last Name" Font-Size="Large" runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtLastName" Font-Size="Large" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label Text="Father Name" Font-Size="Large" runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtFatherName" Font-Size="Large" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label Text="Gender" Font-Size="Large" runat="server"></asp:Label>
</td>
<td>
<asp:RadioButton ID="rdbtnMale" GroupName="Gender" Text="Male" TextAlign="Right" Font-
Size="Large" Checked="true" runat="server" />
<asp:RadioButton ID="rdbtnFemale" GroupName="Gender" Text="Female" TextAlign="Right" Font-
Size="Large" runat="server" />
</td>

</tr>
<tr>
<td>
<asp:Label ID="Label1" Text="Designation" Font-Size="Large" runat="server"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlDesignation" Font-Size="Large" runat="server" Width="100%">
<asp:ListItem>GM</asp:ListItem>
<asp:ListItem>Manager</asp:ListItem>
<asp:ListItem>Staff Member</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" Text="Shift" Font-Size="Large" runat="server"></asp:Label>
</td>
<td>
<asp:RadioButton ID="rdbtnMorning" GroupName="Shift" Text="Male" TextAlign="Right" Font-
Size="Large" Checked="true" runat="server" />
<asp:RadioButton ID="rdbtnEvening" GroupName="Shift" Text="Female" TextAlign="Right" Font-
Size="Large" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblStatus" runat="server" Text="Status" Visible="False"></asp:Label>
</td>
<td>
<asp:HiddenField ID="txtLat" runat="server" />
<asp:HiddenField ID="txtLong" runat="server" />
<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" Width="100%"
Height="50px" Font-Size="Medium" />
</td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>

protected void btnSave_Click(object sender, EventArgs e)


{
try
{
Response.Write(txtLat.Value.ToString());
Response.Write("\n" + txtLong.Value.ToString());
SqlConnection con = new SqlConnection("Data Source=Fahad-Pc;Initial Catalog=test;Integrated
Security=True;");
SqlCommand cmd = new SqlCommand("Insert into emp Values
('"+txtFirstName.Text+"','"+txtLastName.Text+"','"+txtFatherName.Text+"','"(+rdbtnMale.Checked ?
"Male" : "Female")+"','"+ddlDesignation.SelectedValue+"','"+(rdbtnMorning.Checked ? "Morning" :
"Evening")+"','"+txtLat.Value+"','"+txtLong.Value+"')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
lblStatus.Visible = true;
lblStatus.Text = "Registered Successfuly!";
}
catch (Exception ex)
{
lblStatus.Visible = true;
lblStatus.Text = ex.Message;
}
}

SHOW ON GOOGLE MAP


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">

<script async defer src="https://maps.googleapis.com/maps/api/js?


key=AIzaSyCQZxbNPCTL6Z3HdOTA8furV5nRN3j8oM4&callback=initMap" type="text/javascript"></script>
<script type="text/javascript">
var markers = [
<asp:Repeater ID="rptMarkers" runat="server">
<ItemTemplate>
{
"title": '<%# Eval("Name") %>',
"lat": '<%# Eval("Latitude") %>',
"lng": '<%# Eval("Longitude") %>',
"description": "No Description Available!"
}
</ItemTemplate>
<SeparatorTemplate>
,
</SeparatorTemplate>
</asp:Repeater>
];
</script>
<script type="text/javascript">
window.onload = function () {
var mapOptions = {
center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
for (i = 0; i < markers.length; i++) {
var data = markers[i]
var myLatlng = new google.maps.LatLng(data.lat, data.lng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: data.title
});
(function (marker, data) {
google.maps.event.addListener(marker, "click", function (e) {
infoWindow.setContent(data.description);
infoWindow.open(map, marker);
});
})(marker, data);
}
}
</script>
<div id="dvMap" style="width: 500px; height: 500px">
</div>
</form>
</body>
</html>

public partial class ShowEmployeeOnMap : System.Web.UI.Page


{
SqlConnection con = new SqlConnection("Data Source=Fahad-Pc;Initial
Catalog=test;Integrated Security=True;");
SqlDataAdapter sda;
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
this.LoadMarkersOnMap();
}

private void LoadMarkersOnMap()


{
sda = new SqlDataAdapter("Select FirstName + LastName as
Name,Latitude,Longitude,Description from GoogleMapAssignment", con);
dt = new DataTable();
sda.Fill(dt);
rptMarkers.DataSource = dt;
rptMarkers.DataBind();
}
}

GRID OPERTAION

namespace Grid_View_Operations
{
public partial class Student : System.Web.UI.Page
{
DataAccessLayer dal = new DataAccessLayer();
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
dal.OpenCon();
String gender = "";
if (rdoFemale.Checked == true)
gender = "Female";
else
gender = "Male";
if (FileUpload1.PostedFile == null)
{
lblStatus.Visible = true;
lblStatus.Text = "No Image Selected";
return;
}
string fileName = FileUpload1.PostedFile.FileName;
dal.InsertUpdateDelete("Insert into Student Values ('" + txtRegNo.Text + "','" + txtFirstName.Text + "','"
+ txtLastName.Text + "','" + gender + "','" + txtDescipline.Text + "','" + txtSection.Text + "','" + txtFatherName.Text
+ "','"+fileName+"')");
lblStatus.Visible = true;
FileUpload1.PostedFile.SaveAs(Server.MapPath(@"~\Images\") + fileName);
lblStatus.Text = "Saved Successfully!";
}
catch (Exception ex)
{
lblStatus.Visible = true;
lblStatus.Text = ex.Message;
}
finally
{
dal.CloseCon();
}
}

protected void btnSearch_Click(object sender, EventArgs e)


{
dal.OpenCon();
dt = new DataTable();
dt = dal.GetData("Select * from Student where RegNo = '" + txtRegNo.Text+"'");
if (dt.Rows.Count != 0)
{
txtRegNo.Text = dt.Rows[0][0].ToString();
txtFirstName.Text = dt.Rows[0][1].ToString();
txtLastName.Text = dt.Rows[0][2].ToString();
if (dt.Rows[0][3].ToString() == "Male")
rdoMale.Checked = true;
else
rdoFemale.Checked = true;
txtDescipline.Text = dt.Rows[0][4].ToString();
txtSection.Text = dt.Rows[0][5].ToString();
txtFatherName.Text = dt.Rows[0][6].ToString();
}
else
{
lblStatus.Visible = true;
lblStatus.Text = "No Record Found!";
}
dal.CloseCon();
}

protected void btnUpdate_Click(object sender, EventArgs e)


{
dal.OpenCon();
string gender="";
if(rdoMale.Checked==true)
gender="Male";
else
gender="Female";
if (dt.Rows.Count != 0)
{
dal.InsertUpdateDelete("Update Student set FName='" + txtFirstName.Text + "',LName = '" +
txtLastName.Text + "',Gender = '" + gender + "',Descipline = '" + txtDescipline.Text + "',Section = '" +
txtSection.Text + "',FatherName = +'" + txtFatherName.Text + "' where RegNo = '" + txtRegNo.Text + "'");
lblStatus.Visible = true;
lblStatus.Text = "Updated!";
}
else
{
lblStatus.Visible = true;
lblStatus.Text = "Student Not Found!";
}
dal.CloseCon();
}

protected void btnDelete_Click(object sender, EventArgs e)


{
dal.OpenCon();
dt = new DataTable();
dt = dal.GetData("Select * from Student where RegNo = '" + txtRegNo.Text + "'");
if (dt.Rows.Count != 0)
{
dal.InsertUpdateDelete("Delete from Student where RegNo = '" + txtRegNo.Text + "'");
lblStatus.Visible = true;
lblStatus.Text = "Deleted!";
}
else
{
lblStatus.Visible = true;
lblStatus.Text = "Student Not Found!";
}
}
}
}

DataAccessLayer
namespace Grid_View_Operations
{
public class DataAccessLayer
{
static string constr = @"Data Source=Fahad-PC;Initial Catalog=CMS;Integrated
Security=True;";
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd;
SqlDataAdapter sda;
DataTable dt;
public void OpenCon()
{
if (con.State == ConnectionState.Closed)
con.Open();
}
public void CloseCon()
{
if (con.State == ConnectionState.Open)
con.Close();
}
public void InsertUpdateDelete(string query)
{
cmd = new SqlCommand(query, con);

cmd.ExecuteNonQuery();
}
public DataTable GetData(string query)
{
sda = new SqlDataAdapter(query, con);
dt = new DataTable();
sda.Fill(dt);
return dt;
}
}
}
<asp:GridView ID="GridViewShowStudents" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None"
OnPageIndexChanging="GridViewShowStudents_PageIndexChanging"
OnRowCancelingEdit="GridViewShowStudents_RowCancelingEdit"
OnRowDeleting="GridViewShowStudents_RowDeleting" OnRowEditing="GridViewShowStudents_RowEditing"
OnRowUpdating="GridViewShowStudents_RowUpdating"
OnSelectedIndexChanged="GridViewShowStudents_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="AridNo" HeaderText="Arid No" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Descipline" HeaderText="Descipline" />
<asp:BoundField DataField="FatherName" HeaderText="Father Name" />
<asp:BoundField DataField="Gender" HeaderText="Gender" />
<asp:ImageField DataImageUrlField="ImageName" HeaderText="Image">
<ControlStyle Height="100px" Width="100px" />
</asp:ImageField>
<asp:CommandField ShowSelectButton="True" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>

namespace Grid_View_Operations
{
public partial class StudentGridView : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=Fahad-PC;Initial Catalog=CMS;Integrated Security=True;");
SqlCommand cmd;
SqlDataAdapter sda;
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
Search();
}

protected void Search()


{
sda = new SqlDataAdapter("Select regNo as AridNo,Descipline,Gender,FatherName,fName +' ' +lName as
Name,'~/Images/'+ImageName as ImageName from Student", con);
dt = new DataTable();
sda.Fill(dt);
GridViewShowStudents.DataSource = dt;
GridViewShowStudents.DataBind();
}

protected void GridViewShowStudents_SelectedIndexChanged(object sender, EventArgs e)


{
LabelSelectedStudent.Text = "You selected " + GridViewShowStudents.SelectedRow.Cells[0].Text.ToString();
}

protected void GridViewShowStudents_RowDeleting(object sender, GridViewDeleteEventArgs e)


{
try
{

cmd = new SqlCommand("Delete from Student where RegNo = '" +


GridViewShowStudents.Rows[e.RowIndex].Cells[0].Text + "'", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Search();
LabelSelectedStudent.Text = "Student Deleted!";
}
catch (Exception ex)
{
LabelSelectedStudent.Text = ex.Message;
}
}

protected void GridViewShowStudents_RowEditing(object sender, GridViewEditEventArgs e)


{
GridViewShowStudents.EditIndex = e.NewEditIndex;
Search();
}

protected void GridViewShowStudents_RowUpdating(object sender, GridViewUpdateEventArgs e)


{
try
{
GridViewRow row = GridViewShowStudents.Rows[e.RowIndex];

String reg = ((TextBox)row.Cells[0].Controls[0]).Text;


TextBox name = (TextBox)row.Cells[1].Controls[0];
TextBox desc = (TextBox)row.Cells[2].Controls[0];
TextBox fName = (TextBox)row.Cells[3].Controls[0];
TextBox gender = (TextBox)row.Cells[4].Controls[0];
GridViewShowStudents.EditIndex = -1;
con.Open();
cmd = new SqlCommand(String.Format("Update Student set FName = '{0}', LName = '{1}', Descipline = '{2}',
FatherName = '{3}', Gender = '{4}' where RegNo = '{5}'", name.Text.Split(' ')[0], name.Text.Split(' ')[1], desc.Text,
fName.Text, gender.Text, reg), con);
cmd.ExecuteNonQuery();
con.Close();
LabelSelectedStudent.Text = "Student Updated Successfully!";
Search();
}
catch (Exception ex)
{
LabelSelectedStudent.Text = ex.Message;
}
}

protected void GridViewShowStudents_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)


{
GridViewShowStudents.EditIndex = -1;
Search();
}

protected void GridViewShowStudents_PageIndexChanging(object sender, GridViewPageEventArgs e)


{
GridViewShowStudents.PageIndex = e.NewPageIndex;
Search();
}
}
}

QUERY STRING

<body>
<form id="form1" runat="server">
<div>
<center>
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="NAME"></asp:Label>
</td><td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td><td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="SEARCH" />
</td>
</tr>
<tr>
<td colspan="3">
<asp:GridView ID="GV" runat="server" AutoGenerateColumns="False"
OnSelectedIndexChanged="GV_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="regno" HeaderText="Reg" />
<asp:BoundField DataField="fname" HeaderText="First Name" />
<asp:BoundField DataField="lname" HeaderText="Last Name" />
<asp:CommandField SelectText="Display" ShowSelectButton="True" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</center>

</div>
</form</body>

namespace QueryString
{
public partial class StudentSearchingViaQS : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-JU9G6DU;Initial
Catalog=CRM;Integrated Security=True");
SqlDataAdapter sda;
SqlDataReader sdr;

SqlCommand cmd;
DataTable dt;
string Query = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

Query = "select * from student"; //where Fname='" + TextBox1.Text.Trim() + "'";


con.Open();

sda = new SqlDataAdapter(Query, con);


dt = new DataTable();

sda.Fill(dt);

GV.DataSource = dt;
GV.DataBind();
con.Close();
}

protected void Button1_Click(object sender, EventArgs e)


{
Query = "select * from student where Fname='" + TextBox1.Text.Trim() + "' or lname='" +
TextBox1.Text.Trim() + "' ";
con.Open();

sda = new SqlDataAdapter(Query, con);


dt=new DataTable();

sda.Fill(dt);

GV.DataSource=dt;
GV.DataBind();
con.Close();
}

protected void GV_SelectedIndexChanged(object sender, System.EventArgs e)


{ string r=GV.SelectedRow.Cells[0].Text;
Response.Write(GV.SelectedRow.Cells[0].Text);
Response.Redirect("details.aspx?reg="+r+"");
}
}
}
DETAIL

namespace QueryString
{
public partial class Details : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-JU9G6DU;Initial
Catalog=CRM;Integrated Security=True");
SqlDataAdapter sda;
SqlCommand cmd;
DataTable dt;
SqlDataReader sdr;

protected void Page_Load(object sender, EventArgs e)


{
if (!IsPostBack)
{
// Response.Write(Request.QueryString["reg"]);
Label1.Text = Request.QueryString[0];
FillDropDownDescipline();
con.Open();
cmd = new SqlCommand("select * from student where regno='" + Label1.Text.Trim() + "' ", con);
sdr = cmd.ExecuteReader();
sdr.Read();
TextBox1.Text = sdr[1].ToString();
TextBox2.Text = sdr[2].ToString();
ddlDescipline.SelectedItem.Text = sdr[4].ToString();
if (sdr[3].ToString() == "male")
RadioButton1.Checked = true;
else
RadioButton2.Checked = true;
TextBox3.Text = sdr[5].ToString();
TextBox4.Text = sdr[6].ToString();
con.Close();

}
private void FillDropDownDescipline()
{
con.Open();
sda = new SqlDataAdapter("Select * from prog", con);
dt = new DataTable();
sda.Fill(dt);
ddlDescipline.DataSource = dt;
ddlDescipline.DataTextField = "Descipline";
ddlDescipline.DataBind();
con.Close();
}

protected void Button1_Click(object sender, EventArgs e)


{
con.Open();
string gen="male";
if (RadioButton1.Checked)
gen = "female";

string Query = "update student set fname='" + TextBox1.Text.Trim() + "',lname='" + TextBox2.Text.Trim()


+ "',descipline='" + ddlDescipline.SelectedItem.Text.ToString() + "',gender='" + gen + "',Address='" +
TextBox3.Text.Trim() + "',contact='" + TextBox4.Text.Trim() + "' where regno='" + Label1.Text + "'";
cmd = new SqlCommand(Query, con);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert'(Saved)</script>");
}
}
}

Session Management
namespace SessionManagement
{
public partial class Session : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(Session["id"]!=null)
Response.Redirect("default.aspx");
}

protected void Button1_Click(object sender, EventArgs e)


{
Session["id"] = TextBox1.Text;
Session["pass"] = TextBox2.Text;
Response.Redirect("default.aspx");
// Session.RemoveAll();

}
}
}

namespace SessionManagement
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session["id"].ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
Session.RemoveAll();
Response.Redirect("session.aspx");
}
}
}

You might also like