using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace test
{
public partial class Student : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
hdnSTDID.Value = "Add";
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
string stdName = tbxName.Text;
DBConnection dbConnection = new DBConnection();
if (hdnMode.Value == "Add")
{
string sql = "INSERT INTO Student ([Name]) VALUES ('" + stdName + "')";
dbConnection.ExecuteQuary(sql);
string script = "alert(\"ADDfgfh..!\");";
ScriptManager.RegisterStartupScript(this, this.GetType(),
"ServerControlScript", script, true);
}
if (hdnMode.Value == "Edit")
{
int stdId = int.Parse(hdnSTDID.Value);
string sqlEdite = "UPDATE Student SET Name = '" + stdName + "' WHERE StdId=" + stdId;
dbConnection.ExecuteQuary(sqlEdite);
hdnMode.Value = "Add";
btnSave.Text = "Add";
}
gvStudent.DataBind();
tbxName.Text = "";
}
protected void gvStudent_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
string studentId = gvStudent.Rows[index].Cells[0].Text;
int stdID = int.Parse(studentId);
DBConnection con = new DBConnection();
if (e.CommandName == "Del")
{
string strDelete = "DELETE FROM Student WHERE StdId=" + stdID;
con.ExecuteQuary(strDelete);
gvStudent.DataBind();
}
if (e.CommandName == "Edi")
{
string sqlEdite = "SELECT StdId, Name FROM Student WHERE StdId=" + stdID;
DataSet ds = con.GetData(sqlEdite);
hdnSTDID.Value = ds.Tables[0].Rows[0]["StdId"].ToString();
tbxName.Text = ds.Tables[0].Rows[0]["Name"].ToString();
btnSave.Text = "Edite";
hdnMode.Value = "Edit";
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace test
{
public partial class Student : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
hdnSTDID.Value = "Add";
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
string stdName = tbxName.Text;
DBConnection dbConnection = new DBConnection();
if (hdnMode.Value == "Add")
{
string sql = "INSERT INTO Student ([Name]) VALUES ('" + stdName + "')";
dbConnection.ExecuteQuary(sql);
string script = "alert(\"ADDfgfh..!\");";
ScriptManager.RegisterStartupScript(this, this.GetType(),
"ServerControlScript", script, true);
}
if (hdnMode.Value == "Edit")
{
int stdId = int.Parse(hdnSTDID.Value);
string sqlEdite = "UPDATE Student SET Name = '" + stdName + "' WHERE StdId=" + stdId;
dbConnection.ExecuteQuary(sqlEdite);
hdnMode.Value = "Add";
btnSave.Text = "Add";
}
gvStudent.DataBind();
tbxName.Text = "";
}
protected void gvStudent_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
string studentId = gvStudent.Rows[index].Cells[0].Text;
int stdID = int.Parse(studentId);
DBConnection con = new DBConnection();
if (e.CommandName == "Del")
{
string strDelete = "DELETE FROM Student WHERE StdId=" + stdID;
con.ExecuteQuary(strDelete);
gvStudent.DataBind();
}
if (e.CommandName == "Edi")
{
string sqlEdite = "SELECT StdId, Name FROM Student WHERE StdId=" + stdID;
DataSet ds = con.GetData(sqlEdite);
hdnSTDID.Value = ds.Tables[0].Rows[0]["StdId"].ToString();
tbxName.Text = ds.Tables[0].Rows[0]["Name"].ToString();
btnSave.Text = "Edite";
hdnMode.Value = "Edit";
}
}
}
}
No comments:
Post a Comment