CODE: edit-friend.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="edit-friend.aspx.cs" Inherits="edit_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"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Mobile
</td>
<td>
<asp:TextBox ID="txtMobile" runat="server"></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: edit-friend.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 edit_friend : System.Web.UI.Page
{
FriendDataClassesDataContext db = new FriendDataClassesDataContext();
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
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)
{
FriendDetail.FriendName = txtFriendName.Text;
FriendDetail.Mobile = txtMobile.Text;
db.SubmitChanges();
}
}
}
No comments:
Post a Comment