CODE : delete-friebnd.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="delete-friend.aspx.cs" Inherits="delete_friend" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
Friend Name
</td>
<td>
<asp:TextBox ID="txtFriendName" runat="server" Enabled="false"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Mobile
</td>
<td>
<asp:TextBox ID="txtMobile" runat="server" Enabled="false"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
CODE : delete-friebnd.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 delete_friend : System.Web.UI.Page
{
FriendDataClassesDataContext db = new FriendDataClassesDataContext();
protected void Page_Load(object sender, EventArgs e)
{
var FriendID = Convert.ToString(Request.QueryString["frndid"]);
var FriendDetail = (from a in db.dbFriends
where a.FriendID == Convert.ToInt32(FriendID)
select a).FirstOrDefault();
if (FriendDetail != null)
{
txtFriendName.Text = FriendDetail.FriendName;
txtMobile.Text = FriendDetail.Mobile;
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
var FriendID = Convert.ToString(Request.QueryString["frndid"]);
var FriendDetail = (from a in db.dbFriends
where a.FriendID == Convert.ToInt32(FriendID)
select a).FirstOrDefault();
if (FriendDetail != null)
{
db.dbFriends.DeleteOnSubmit(FriendDetail);
db.SubmitChanges();
}
}
}
No comments:
Post a Comment