Remember Me
forgot your password?

Simple & Complete Gridview Functionality(dotnet 2.0) by Syed Shees Abidi

My this article covers GridView functionality in a Complte,Simple & Precise way in ASP.NET(2.0), C#,(SQLServer 2005 backend). This article provides a single GridView which is capable of
~Displaying Data from database,
~Updateing it if required,
~Deleting the existing records from database based on a Confirmation Message and
~Inserting a new record(which is beyond the implicit usage of GridView).

NOTE: The application requires three simple stored procedures named empins,empupd,empdel for updation insertion and deletion respectively.

           Gridview Update Source

     
                   
        

               
                     
       

    Delete??

                   
                       
                                                        Width="61px">
                       
                       
                            Employee ID
                       
                       
                           
                       
                   
                   
                       
                           
                       
                       
                            Employee Name
                       
                       
                           
                       
                   
                   
                       
                           
                       
                       
                            Contact No
                       
                       
                           
                       
                   
               
                      

    Gridview Update C# Source Code:>/u>

using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) BindData(); }

private void BindData() { try { string connectionString = "Data Source=MDYNYCCMTDEV;Initial Catalog=pubs;User ID=rast;Password=rast05"; string commandString = "select * from Employee1 order by EmployeeID asc"; SqlConnection con = new SqlConnection(connectionString); SqlDataAdapter da = new SqlDataAdapter(commandString, con); con.Open(); DataSet ds = new DataSet(); da.Fill(ds);

GridView1.DataSource = ds; GridView1.DataBind(); con.Close(); } catch (Exception ex) { Response.Write(ex.Message); } }

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; BindData(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { if (((LinkButton)GridView1.Rows[0].Cells[0].Controls[0]).Text == "Insert") { TextBox TextBox1; string EmployeeName, ContactNo; TextBox1 = (TextBox)GridView1.Rows[0].FindControl("txtEmployeeName"); EmployeeName = TextBox1.Text; TextBox1 = (TextBox)GridView1.Rows[0].FindControl("txtContactNo"); ContactNo = TextBox1.Text;

SqlConnection con = new SqlConnection("Data Source=MDYNYCCMTDEV;Initial Catalog=pubs;User ID=rast;Password=rast05");

SqlCommand cmd = new SqlCommand("empins", con); cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@EmployeeName", SqlDbType.VarChar, 50); cmd.Parameters.Add("@ContactNo", SqlDbType.VarChar, 50);

cmd.Parameters["@EmployeeName"].Value = EmployeeName; cmd.Parameters["@ContactNo"].Value = ContactNo;

con.Open();

cmd.ExecuteNonQuery();

con.Close(); GridView1.EditIndex = -1;

BindData();

}

else {

Label Label1; TextBox TextBox1;

string EmployeeID, EmployeeName, ContactNo; Label1 = (Label)GridView1.Rows[e.RowIndex].FindControl("lblEmployeeIDEdit"); EmployeeID = Label1.Text; TextBox1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEmployeeName"); EmployeeName = TextBox1.Text; TextBox1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtContactNo"); ContactNo = TextBox1.Text;

SqlConnection con = new SqlConnection("Data Source=MDYNYCCMTDEV;Initial Catalog=pubs;User ID=rast;Password=rast05"); SqlCommand cmd = new SqlCommand("empupd", con); cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@EmployeeID", SqlDbType.Int); cmd.Parameters.Add("@EmployeeName", SqlDbType.VarChar, 50); cmd.Parameters.Add("@ContactNo", SqlDbType.VarChar, 50);

cmd.Parameters["@EmployeeID"].Value = EmployeeID; cmd.Parameters["@EmployeeName"].Value = EmployeeName; cmd.Parameters["@ContactNo"].Value = ContactNo;

con.Open(); cmd.ExecuteNonQueryon.Close();

GridView1.EditIndex = -1;

BindData(); }

}

 

protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView1.EditIndex = -1; BindData(); }

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { Label Label1; string EmployeeID;

Label1 = (Label)GridView1.Rows[e.RowIndex].FindControl("lblEmployeeID");

EmployeeID = Label1.Text;

SqlConnection con = new SqlConnection("Data Source=MDYNYCCMTDEV;Initial Catalog=pubs;User ID=rast;Password=rast05"); SqlCommand cmd = new SqlCommand("empdel", con); cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@EmployeeID", SqlDbType.Int); cmd.Parameters["@EmployeeID"].Value = EmployeeID;

con.Open(); cmd.ExecuteNonQuery(); con.Close();

GridView1.EditIndex = -1;

BindData(); }

protected void btnaddrec_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=MDYNYCCMTDEV;Initial Catalog=pubs;User ID=rast;Password=rast05"); SqlDataAdapter da = new SqlDataAdapter("SELECT * from Employee1", con); DataTable dt = new DataTable(); da.Fill(dt);

DataRow dr = dt.NewRow(); dt.Rows.InsertAt(dr, 0);

GridView1.EditIndex = 0; GridView1.DataSource = dt; GridView1.DataBind();

((LinkButton)GridView1.Rows[0].Cells[0].Controls[0]).Text = "Insert"; } }

 

My this article covers GridView functionality in a Complte,Simple & Precise way in ASP.NET(2.0), C#,(SQLServer 2005 backend). This article provides a single GridView which is capable of
~Displaying Data from database,
~Updateing it if required,
~Deleting the existing records from database based on a Confirmation Message and
~Inserting a new record(which is beyond the implicit usage of GridView).

NOTE: The application requires three simple stored procedures named empins,empupd,empdel for updation insertion and deletion respectively.

About the Author

Syed Shees Abidi, Syntel Ltd., Mumbai(India) Home Place:Lucknow

 

Shees Abidi

Syed Shees Abidi,

Syntel Ltd.,

Mumbai(India)

Home Place:Lucknow

Rate this Article: 5 / 5 stars - 1 vote(s)
Print Email Re-Publish


Article Source: http://www.articlesbase.com/programming-articles/simple-complete-gridview-functionalitydotnet-20-by-syed-shees-abidi-622528.html
Add new Comment



Captcha

  • Latest Programming Articles
  • More from Shees Abidi

php software development company

By: usha sharma | 08/07/2009
Professional Web Development Company phpmaestro provides custom website development web application development ecommerce website design and development services. Custom web application development services and professional website development at affordable rates from phpmaestro Company. www.phpmaestro.com is a php Application Development Shopping Cart for e-commerce stores. Our shopping cart software gives our client full control over your online shop its products design development prices sh

Hire ASP .Net Developers Hire Dedicated ASP.Net Developers Offshore ASP.Net Programmers

By: Arshad | 08/07/2009
Since the concept of outsourcing changed the economy of many countries it has been very clear that paying Indian development service providers is very much economical than funding an in-house private team. Analysis says that more than 50% of the cost can be saved by inking contracts with Indian IT service providers.

Windbg Minidump Tutorial:Setting up & Reading Minidump Files

By: Jeannie Lee | 07/07/2009
Windgb Minidump tutorial to set up and read minidump files (.dmp). Setting Symbol File Path. Output of Windbg command. windbg.exe -z [file path to minidump file.dmp] -c !analyze -v.

Javascript Validate Name Field

By: Jeannie Lee | 07/07/2009
Simple Javascript tutorial on validating a name field. Checks to see if there is a value in the name field with Javascript after the user submits a form.

Logo Design- The image creator!

By: Jhonny Sharma | 07/07/2009
Brand image is something that many consumers look for while buying a product. Brand image and brand positioning have become important concepts in the corporate world. When image building strategies are talked about, what tops the list is a creative logo design.

Design principles in logo

By: Jhonny Sharma | 07/07/2009
An element of balance is a mandatory aspect of design. A design is considered to be a great design when it incorporates all design aspects in the required proportion. The design principles are vital for any kind of design.

Organization specific software

By: Manish Shrivastava | 07/07/2009
Different businesses have different technological needs depending upon the type of work they are engaged in. Some businesses might require minimum use of software technology where there might be others whose very business might depend upon the optimum use of technology.

Hire .Net Developers: Hire ASP.Net Programmers

By: Arshad | 07/07/2009
Since the concept of outsourcing changed the economy of many countries it has been very clear that paying Indian development service providers is very much economical than funding an in-house private team. Analysis says that more than 50% of the cost can be saved by inking contracts with Indian IT service providers.

Simple & Complete Gridview Functionality(dotnet 2.0) by Syed Shees Abidi

By: Shees Abidi | 31/10/2008 | Programming
My this article covers GridView functionality in a Complte,Simple & Precise way in ASP.NET(2.0),C#,SQLServer 2005.This article provides a single GridView which is capable of ~Displaying Data ~Updating it ~Deleting the existing records from database based on a Confirmation Message and ~Inserting a new record(which is beyond the implicit usage of GridView). NOTE: The application requires three simple stored proc. named empins,empupd,empdel for updation insertion and deletion respectively

Submit Your Articles Free: Signup


Article Categories




Use of this web site constitutes acceptance of the Terms Of Use and Privacy Policy | User published content is licensed under a Creative Commons License.
Copyright © 2005-2008 Free Articles by ArticlesBase.com, All rights reserved. (0.19, 1)