Show A List of Courses From Databases (Course Enrollment System) and Apply CRUD
Show A List of Courses From Databases (Course Enrollment System) and Apply CRUD
Show a list of courses from databases (Course Enrollment System) and apply
CRUD operations using gridview control.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>
Course Enrollment System
</h1><br />
<asp:GridView ID="gridService" runat="server" OnRowDeleting="gridService_RowDeleting"
DataKeyNames="id" OnRowEditing="gridService_RowEditing" OnRowUpdating="gridService_RowUpdating"
OnRowCancelingEdit="gridService_RowCancelingEdit">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace labb13
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BindGrid();
}
cmd.Parameters.AddWithValue("@Name", name1);
cmd.ExecuteNonQuery();
con.Close();
gridService.EditIndex = -1;
this.BindGrid();
}
public void BindGrid()
{
string query = "select * from Course";
string connectionstring = @"Data Source=DESKTOP-2S589NA;Initial Catalog=lab13;Integrated Security=True";
SqlConnection con = new SqlConnection(connectionstring);
con.Open();
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds, "Course");
con.Close();
gridService.DataSource = ds.Tables["Course"];
gridService.DataBind();
}
}
}