Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 14409 |  Welcome, Guest!   Register  Login
 Home > Forums > C# > how can do gridview insert,update,edit,delete event in asp.net c# ...
Sekar.C

how can do gridview insert,update,edit,delete event in asp.net c#

Replies: 7 | Posted by: Sekar.C on 5/18/2012 | Category: C# Forums | Views: 7628 | Status: [Member] | Points: 10  


Hi,
please help me.how can do gridview insert,update,edit,delete event in asp.net c#.

Regards
Sekar.c

Regards
Sekar.c


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Kkdubey
Kkdubey  
Posted on: 5/18/2012 9:54:01 AM
Level: Starter | Status: [Member] | Points: 25

hi,
but sorry , i am confused from your question that,
" how can do gridview insert,update,edit,delete event in asp.net c#."
please explain me.......

Regards,
Krishna

Sekar.C, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Sekar.C
Sekar.C  
Posted on: 5/18/2012 10:03:56 AM
Level: Starter | Status: [Member] | Points: 25

Hi krishna,
I need to update table value throw gridview eg:after display the values in grid I click edit button this update operation is do.
Regards
sekar.c

Regards
Sekar.c

Sekar.C, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Iluvdotnetfunda
Iluvdotnetfunda  
Posted on: 5/18/2012 10:11:27 AM
Level: Starter | Status: [Member] | Points: 25

Sekar.C, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Ksuresh
Ksuresh  
Posted on: 5/19/2012 1:42:15 AM
Level: Starter | Status: [Member] | Points: 25

Hi Sekar,

Learn more about Grid view functionality form below link, This helps you to get more knowledge .....
http://www.dotnetfunda.com/articles/article1655-22-gridview-tips-and-tricks-by-sheo-narayan.aspx

Thanks
Suresh

Sekar.C, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Sekar.C
Sekar.C  
Posted on: 5/19/2012 2:14:31 AM
Level: Starter | Status: [Member] | Points: 25

Hi,
i got the solution thanks for your response.
Regards
Sekar.c

Regards
Sekar.c

Sekar.C, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Pravesh Singh
Pravesh Singh  
Posted on: 4/9/2013 7:08:21 AM
Level: Starter | Status: [Member] | Points: 25

Hi Everyone!

If you want to used custom buttons for edit, delete, update and insert operation then you can prefer below link

http://mindstick.com/Articles/38ca3305-6346-467e-b03b-a536737ff623/?Insert%20Delete%20Update%20in%20Gr#dvHeaderText

Hope it is very useful to all

Pravesh Singh

Sekar.C, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Satyapriyanayak
Satyapriyanayak  
Posted on: 4/9/2013 7:27:45 AM
Level: Bronze | Status: [Member] | Points: 25

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
//SqlConnection conn = new SqlConnection(connStr);
SqlDataAdapter ad = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
DataTable dataTable;
SqlDataAdapter sqlda;
DataSet ds;
string str;
protected void Page_Load(object sender, EventArgs e)
{
Session["sortBy"] = null;
if (!IsPostBack)
{
FillVendorGrid();
}
}
private void FillVendorGrid()
{
SqlConnection conn = new SqlConnection(connStr);
dataTable = new DataTable();
cmd.Connection = conn;
cmd.CommandText = "SELECT * FROM Vendor";
ad = new SqlDataAdapter(cmd);
ad.Fill(dataTable);
ResultGridView.DataSource = dataTable;
ResultGridView.DataBind();

}

protected void ResultGridView_RowEditing(object sender, GridViewEditEventArgs e)
{
ResultGridView.EditIndex = e.NewEditIndex;
FillVendorGrid();
}


protected void ResultGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
ResultGridView.PageIndex = e.NewPageIndex;
FillVendorGrid();
}

protected void ResultGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlConnection conn = new SqlConnection(connStr);
cmd.Connection = conn;
cmd.CommandText = "DELETE FROM Vendor WHERE VendorId='" + ResultGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'";
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
FillVendorGrid();

}

protected void ResultGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtFName = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtFName");
TextBox txtLName = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtLName");
TextBox txtCity = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtCity");
TextBox txtState = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtState");
TextBox txtCountry = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtCountry");
TextBox txtDescription = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtDescription");

SqlConnection conn = new SqlConnection(connStr);
cmd.Connection = conn;
cmd.CommandText = "UPDATE Vendor SET VendorFName ='" + txtFName.Text + "',VendorLName ='" + txtLName.Text + "',VendorCity ='" + txtCity.Text + "',VendorState ='" + txtState.Text + "',VendorCountry ='" + txtCountry.Text + "',VendorDescription ='" + txtDescription.Text + "' WHERE VendorId='" + ResultGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'";
conn.Open();
cmd.ExecuteNonQuery();
ResultGridView.EditIndex = -1;
FillVendorGrid();
conn.Close();

}

protected void ResultGridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
ResultGridView.EditIndex = -1;
FillVendorGrid();

}

protected void ResultGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddNew"))
{

TextBox txtFName = (TextBox)ResultGridView.FooterRow.FindControl("txtFName1");
TextBox txtLName = (TextBox)ResultGridView.FooterRow.FindControl("txtLName1");
TextBox txtCity = (TextBox)ResultGridView.FooterRow.FindControl("txtCity1");
TextBox txtState = (TextBox)ResultGridView.FooterRow.FindControl("txtState1");
TextBox txtCountry = (TextBox)ResultGridView.FooterRow.FindControl("txtCountry1");
TextBox txtDescription = (TextBox)ResultGridView.FooterRow.FindControl("txtDescription1");
SqlConnection conn = new SqlConnection(connStr);
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO Vendor(VendorFName, VendorLName,VendorCity,VendorState,VendorCountry,VendorDescription) Values('" + txtFName.Text + "', '" + txtLName.Text + "', '" + txtCity.Text + "', '" + txtState.Text + "', '" + txtCountry.Text + "' , '" + txtDescription.Text + "')";
conn.Open();
cmd.ExecuteNonQuery();
FillVendorGrid();
conn.Close();
}
}
protected void btn_search_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
str = "select * from Vendor where VendorFName like '" + TextBox1.Text + "%'";
cmd = new SqlCommand(str, conn);
sqlda = new SqlDataAdapter(cmd);
ds = new DataSet();
sqlda.Fill(ds, "Vendor");
conn.Close();

ResultGridView.DataSource = ds;
ResultGridView.DataMember = "Vendor";
ResultGridView.DataBind();

}
protected void ResultGridView_Sorting(object sender, GridViewSortEventArgs e)
{
Session["sortBy"] = e.SortExpression;
FillVendorGrid();
}
}

Sekar.C, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

Found interesting? Add this to:


 Latest Posts

Write New Post | More ...

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/20/2013 9:25:48 AM