using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.IO; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { FillGridView(); } } private void FillGridView() { try { string cnString = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString; SqlConnection con = new SqlConnection(cnString); GlobalClass.adap = new SqlDataAdapter("select * from TechnisionStatus", con); SqlCommandBuilder bui = new SqlCommandBuilder(GlobalClass.adap); GlobalClass.dt = new DataTable(); GlobalClass.adap.Fill(GlobalClass.dt); GridView1.DataSource = GlobalClass.dt; GridView1.DataBind(); } catch { Response.Write("<script>alert('ConnectionString Error...')</script>"); } } protected void editRecord(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; FillGridView(); } protected void cancelRecord(object sender, GridViewCancelEditEventArgs e) { GridView1.EditIndex = -1; FillGridView(); } protected void AddNewRecord(object sender, EventArgs e) { try { if (GlobalClass.dt.Rows.Count > 0) { GridView1.EditIndex = -1; GridView1.ShowFooter = true; FillGridView(); } else { GridView1.ShowFooter = false; DataRow dr = GlobalClass.dt.NewRow(); dr["Date"] = 0; dr["TechnisionName"] = 0; dr["Task"] = 0; dr["Status"] = 0; dr["Remark"] = 0; GlobalClass.dt.Rows.Add(dr); GridView1.DataSource = GlobalClass.dt; GridView1.DataBind(); GridView1.Rows[0].Visible = true; } } catch { Response.Write("<script> alert('Row not added in DataTable...') </script>"); } } protected void AddNewCancel(object sender, EventArgs e) { GridView1.ShowFooter = false; FillGridView(); } protected void InsertNewRecord(object sender, EventArgs e) { try { string strName = GlobalClass.dt.Rows[0]["TechnisionName"].ToString(); if (strName == "0") { GlobalClass.dt.Rows[0].Delete(); GlobalClass.adap.Update(GlobalClass.dt); } TextBox txtDate = GridView1.FooterRow.FindControl("txtNewDate") as TextBox; TextBox txtName = GridView1.FooterRow.FindControl("txtNewName") as TextBox; TextBox txtTask = GridView1.FooterRow.FindControl("txtNewTask") as TextBox; TextBox txtStatus = GridView1.FooterRow.FindControl("txtNewStatus") as TextBox; TextBox txtRemark = GridView1.FooterRow.FindControl("txtNewRemark") as TextBox; DataRow dr = GlobalClass.dt.NewRow(); dr["Date"] = txtDate.Text.Trim(); dr["TechnisionName"] = txtName.Text.Trim(); dr["Task"] = txtTask.Text.Trim(); dr["Status"] = txtStatus.Text.Trim(); dr["Remark"] = txtRemark.Text.Trim(); GlobalClass.dt.Rows.Add(dr); GlobalClass.adap.Update(GlobalClass.dt); GridView1.ShowFooter = false; FillGridView(); } catch { Response.Write("<script> alert('Record not added...') </script>"); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)