Add this in webform1.aspx
<script>
function Getid(id)
{
//alert(id);
window.location.href="update.aspx?id="+id;
}
</script>
------------------------------------------------
update.aspx code:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="update.aspx.cs" Inherits="crud.update" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="row" style="height:250px;border:1px inset gray;margin-bottom:20px;">
<div class="container">
<table class="table table-responsive">
<tr>
<td>NAME</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" CssClass="form-control"></asp:TextBox>
</td>
</tr>
<tr>
<td>Gneder</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>--Select--</asp:ListItem>
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Femle</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Button1" runat="server" Text="Update" CssClass="btn btn-success" OnClick="Button1_Click" />
</td>
</tr>
</table>
</div>
</div>
</asp:Content>
------------------------------
using crud.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace crud
{
public partial class update : System.Web.UI.Page
{
db_aspnetEntities db = new db_aspnetEntities();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["id"] != null)
{
int id = Convert.ToInt32(Request.QueryString["id"]);
tbl_employee emp = db.tbl_employee.Where(x => x.emp_id == id).SingleOrDefault();
TextBox1.Text = emp.emp_name;
DropDownList1.SelectedValue = emp.emp_gender;
}
else
{
Response.Redirect("~/WebForm1.aspx");
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(Request.QueryString["id"]);
tbl_employee emp = db.tbl_employee.Where(x => x.emp_id == id).SingleOrDefault();
emp.emp_name = TextBox1.Text;
emp.emp_gender = DropDownList1.SelectedValue.ToString();
emp.emp_modifieddate = DateTime.Now;
db.SaveChanges();
Response.Redirect("~/WebForm1.aspx");
}
}
}
My Name Is Salman Masood , I am Computer Science &Amp; Maths Graduate from University of Karachi, Pakistan , Teaching Is My Passion and My Aim Is to Deliver All My Knowledge among Those Students Who Can'T Afford Tutors or Expensive Institute Fees. I Will Be Keep Sharing My All Knowledge and Information with You .... Remember Me in Your Prayers !
Wednesday, 10 April 2019
Linq to Sql entity framework in asp net webform part 2 | asp.net web for...
Subscribe to:
Posts (Atom)
Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC
Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...
-
Load event: pictureBox3.Image = Image .FromFile( @"C:\Users\salman\Documents\Visual Studio 2013\Projects\WindowsFormsApplication3\W...