Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Asp.net insert, Edit, update, delete data in gridview

Feb 9, 2011
Introduction:

In this article I will explain how to insert, edit, update and delete data in gridview using asp.net.


Description:

I have one gridview I need to write code to insert data into gridview after that I need to edit that gridview data and update it and if I want to delete the record in grdview we need to delete record simply by click on delete button of particular row to achieve these functionalities I have used some of gridview events those are 

1        1) Onrowcancelingedit
2        2) Onrowediting
3        3) Onrowupdating
4        4) Onrowcancelingedit
5        5) Onrowdeleting

By Using above griview events we can insert, edit, update and delete the data in gridview. My Question is how we can use these events in our coding before to see those details first design  table in database and give name Employee_Details
ColumnName
DataType
UserId
Int(set identity property=true)
UserName
varchar(50)
City
varchar(50)
Designation
varchar(50)
After completion table creation design aspx page like this
 

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.Gridview
{
font-family:Verdana;
font-size:10pt;
font-weight:normal;
color:black;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvDetails" DataKeyNames="UserId,UserName" runat="server"
AutoGenerateColumns="false" CssClass="Gridview" HeaderStyle-BackColor="#61A6F8"
ShowFooter="true" HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="White"
onrowcancelingedit="gvDetails_RowCancelingEdit"
onrowdeleting="gvDetails_RowDeleting" onrowediting="gvDetails_RowEditing"
onrowupdating="gvDetails_RowUpdating"
onrowcommand="gvDetails_RowCommand">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:ImageButton ID="imgbtnUpdate" CommandName="Update" runat="server" ImageUrl="~/Images/update.jpg" ToolTip="Update" Height="20px" Width="20px" />
<asp:ImageButton ID="imgbtnCancel" runat="server" CommandName="Cancel" ImageUrl="~/Images/Cancel.jpg" ToolTip="Cancel" Height="20px" Width="20px" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="imgbtnEdit" CommandName="Edit" runat="server" ImageUrl="~/Images/Edit.jpg" ToolTip="Edit" Height="20px" Width="20px" />
<asp:ImageButton ID="imgbtnDelete" CommandName="Delete" Text="Edit" runat="server" ImageUrl="~/Images/delete.jpg" ToolTip="Delete" Height="20px" Width="20px" />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="imgbtnAdd" runat="server" ImageUrl="~/Images/AddNewitem.jpg" CommandName="AddNew" Width="30px" Height="30px" ToolTip="Add new User" ValidationGroup="validaiton" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UserName">
<EditItemTemplate>
<asp:Label ID="lbleditusr" runat="server" Text='<%#Eval("Username") %>'/>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblitemUsr" runat="server" Text='<%#Eval("UserName") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtftrusrname" runat="server"/>
<asp:RequiredFieldValidator ID="rfvusername" runat="server" ControlToValidate="txtftrusrname" Text="*" ValidationGroup="validaiton"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City">
<EditItemTemplate>
<asp:TextBox ID="txtcity" runat="server" Text='<%#Eval("City") %>'/>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblcity" runat="server" Text='<%#Eval("City") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtftrcity" runat="server"/>
<asp:RequiredFieldValidator ID="rfvcity" runat="server" ControlToValidate="txtftrcity" Text="*" ValidationGroup="validaiton"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Designation">
<EditItemTemplate>
<asp:TextBox ID="txtDesg" runat="server" Text='<%#Eval("Designation") %>'/>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblDesg" runat="server" Text='<%#Eval("Designation") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtftrDesignation" runat="server"/>
<asp:RequiredFieldValidator ID="rfvdesignation" runat="server" ControlToValidate="txtftrDesignation" Text="*" ValidationGroup="validaiton"/>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div>
<asp:Label ID="lblresult" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
Now add the following namespaces in codebehind


using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing
After that write the following code


SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindEmployeeDetails();
}
}
protected void BindEmployeeDetails()
{
con.Open();
SqlCommand cmd = new SqlCommand("Select * from Employee_Details", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count > 0)
{
gvDetails.DataSource = ds;
gvDetails.DataBind();
}
else
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gvDetails.DataSource = ds;
gvDetails.DataBind();
int columncount = gvDetails.Rows[0].Cells.Count;
gvDetails.Rows[0].Cells.Clear();
gvDetails.Rows[0].Cells.Add(new TableCell());
gvDetails.Rows[0].Cells[0].ColumnSpan = columncount;
gvDetails.Rows[0].Cells[0].Text = "No Records Found";
}
}
protected void gvDetails_RowEditing(object sender, GridViewEditEventArgs e)
{
gvDetails.EditIndex = e.NewEditIndex;
BindEmployeeDetails();
}
protected void gvDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int userid = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Value.ToString());
string username = gvDetails.DataKeys[e.RowIndex].Values["UserName"].ToString();
TextBox txtcity = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtcity");
TextBox txtDesignation = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtDesg");
con.Open();
SqlCommand cmd = new SqlCommand("update Employee_Details set City='" + txtcity.Text + "',Designation='" + txtDesignation.Text + "' where UserId=" + userid, con);
cmd.ExecuteNonQuery();
con.Close();
lblresult.ForeColor = Color.Green;
lblresult.Text = username + " Details Updated successfully";
gvDetails.EditIndex = -1;
BindEmployeeDetails();
}
protected void gvDetails_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvDetails.EditIndex = -1;
BindEmployeeDetails();
}
protected void gvDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int userid = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Values["UserId"].ToString());
string username = gvDetails.DataKeys[e.RowIndex].Values["UserName"].ToString();
con.Open();
SqlCommand cmd = new SqlCommand("delete from Employee_Details where UserId=" + userid, con);
int result = cmd.ExecuteNonQuery();
con.Close();
if (result == 1)
{
BindEmployeeDetails();
lblresult.ForeColor = Color.Red;
lblresult.Text = username + " details deleted successfully";
}
}
protected void gvDetails_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName.Equals("AddNew"))
{
TextBox txtUsrname = (TextBox)gvDetails.FooterRow.FindControl("txtftrusrname");
TextBox txtCity = (TextBox)gvDetails.FooterRow.FindControl("txtftrcity");
TextBox txtDesgnation = (TextBox) gvDetails.FooterRow.FindControl("txtftrDesignation");
con.Open();
SqlCommand cmd =
new SqlCommand(
"insert into Employee_Details(UserName,City,Designation) values('" + txtUsrname.Text + "','" +
txtCity.Text + "','" + txtDesgnation.Text + "')", con);
int result= cmd.ExecuteNonQuery();
con.Close();
if(result==1)
{
BindEmployeeDetails();
lblresult.ForeColor = Color.Green;
lblresult.Text = txtUsrname.Text + " Details inserted successfully";
}
else
{
lblresult.ForeColor = Color.Red;
lblresult.Text = txtUsrname.Text + " Details not inserted";
}
}
}
Demo


Download sample code attached

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

231 comments :

«Oldest   ‹Older   1 – 200 of 231   Newer›   Newest»
Anonymous said...

Good one it helped a lot

Anonymous said...

thx

naresh said...

hey really awesome..can i ve ur number..i feel vry proud to ve ur number in my mobile..awesome dude..keep helping..

* MOON * said...

Can i know the explanation of each of the tag used in above example..

Anonymous said...

Thanks Boss, this is best site for IT Languages and database.

K. Mohan Kumar said...

Good start suresh...Your articles are excellent!!!! Great stuff...

Anupam said...

really helpfull.Its working quit faster.

thanx for sharing

Phalguni Bhuyan said...

excellent one but while deleting a record the confirmation is not cumming which is written using JavaScript function

Phalguni Bhuyan said...

Can you give your number please

Amar Prasad said...

Hi sir,
i have 3 buttons Add/Update/Delete in my Grid View,..Plz, sir can u say me how to ADD/UPDATE/DELETE images in Grid View...

Plz,mail me on tech.amarprasad@gmail.com

sunitha said...

i can't understand how to insert,update and delete in gridview .please explain briefly.

sunitha said...

gud mrng sir,i want this as in 3-tier.please explain sir

Anonymous said...

thanx ... its a relaay nice post

vignesh priya said...

hi sir, in the above program updating and deleting is not working. mainly that Convert.Int32 line shows error due to invalid method arguments. please found me a solution.

khusboo said...

i got problem in con.open() plz help me my mind is gng to blast...plzzzzzzz help me soon...

Shubham Vijay said...

very useful..

Bill said...

Excellent! It was so good I'm now using it! Thank you for sharing!

Bill said...

If you having a problem at con.open() it is because there is no database. Right click on App_Data, and add new item . SQL Server Database and name it anything you want. Add a table, and add 4 columns, called
UserID int (make this primary key and also make it auto increment by adjusting the column properties to Identity Specification to YES)
and three others called UserName, City, Designation (all strings or nchar(40))
Save this table as Employee_Details. Right click on the database and select properties. Copy the whole connection string and paste into line #17 where the string starts with Data Source=. When you start the sample it should run!

Unknown said...

best one sir really very helpfull sir.
And thanks for sharing
God bless you.

Anonymous said...

First of all thanks,
iam running the Project i got one Error that is:

Object reference not set to an instance of an object.

in the Update and Delete button

plz give me Suggession For this....Iam waiting for Replay

Thank You,
Yours Faithfully,
Basha

ketan said...

hellloooo..
i need "drag and drop items from one list to another list " code

yr other code very usefull to me.its so eazy....
plz.... send me on my email id"ketan_coolboy@ymail.com"

ann said...

Can i include an imageicon in the gridview columns

Unknown said...

Hi sir, my name is singamalai.
in the above code
i'm getting the default value instead of
updated value in TextBox txtcity,

If anybody knows, please mail the code to simhamalai@yahoo.com

Anonymous said...

Great...
But sir, I want to hide all the information from gridview after saved.
When serach then it will come up. So please help me. My email-id: rd.666@rediffmail.com

Thank you Sir.

Anonymous said...

Thanks,Was confusing before this one but now clear as i was did this earlier but through direct DSN.
Issac.

Srinivasa said...

Very very Thanks suresh . freshers or exp helpfull to this website

dinesh kumar said...

Im facing error like this:::(Object reference not set to an instance of an object.)plz help me sir.

ganesh0025 said...

else
{
lblresult.ForeColor = Color.Red;
lblresult.Text = txtUsrname.Text + " Details not inserted";
}

above code is not working properly plz check ot naresh..
rply me below email id.
my mail id:
ganesh0025@gmail.com

benita said...

hhkjhjk

Gutenberg Alexis Torres Brousset Pacheco said...

Gracias, muy bueno.

bhuvanashree venkatesan said...

i don have any words bro. u are a DOTNET-GOD

Anonymous said...

really nice work

anusha said...

only insert in working...when click delete it will go to row command..pls help me out

anusha said...

anyone pls help me..

anusha said...

void grid()
{
SqlCommand cmd = new SqlCommand("Select * from TEST1", cn);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ad.Fill(ds);
cn.Close();
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
else
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
GridView1.DataSource = ds;
GridView1.DataBind();
int columncount = GridView1.Rows[0].Cells.Count;
GridView1.Rows[0].Cells.Clear();
GridView1.Rows[0].Cells.Add(new TableCell());
GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
GridView1.Rows[0].Cells[0].Text = "No Records Found";
}
}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
TextBox t1 = (TextBox)GridView1.FooterRow.FindControl("TextBox1");
TextBox t2 = (TextBox)GridView1.FooterRow.FindControl("TextBox2");
TextBox t3 = (TextBox)GridView1.FooterRow.FindControl("TextBox3");
cn.Open();

cmd = new SqlCommand("insert into TEST1(name,email,age) values('" + t1.Text + "','" + t2.Text + "','" + t3.Text + "')", cn);
cmd.ExecuteNonQuery();
Response.Write("inserted");
grid();
cn.Close();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string Name = GridView1.DataKeys[e.RowIndex].Values["name"].ToString();
cn.Open();
cmd = new SqlCommand("delete from TEST1 where name="+Name, cn);

//cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = GridView1.Rows[e.RowIndex].Cells[2].Text;
cmd.ExecuteNonQuery();
Response.Write("deleted");
grid();
cn.Close();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
grid();
}

anusha said...

pls help me my above code is not working properly in while deleting

Suresh Dasari said...

@Anusha...
Pls check whether you gave CommandName="Delete" for your delete button or not.

Yagnesh Dixit said...

Great work Suresh.... I dont know if I will really use it or not but I like the tidy and well structured and ready to use code of yours... Keep going......

Anonymous said...

good yar excelent...........

ram krishna said...

vamsi
------
error
------
Object reference not set to an instance of an object


soluction
---------
once check web.config page

SANTHOSH said...

I am always preferring you site only boss....

Shruthi said...

Hi,
A very helpful post.. It was really easy to understand.. Thanks a lot..:)

RAJEEV RANJAN said...

hello sir thank you for this very very helpfull tutorials its work fine .but i have a problem

when i insrted string value in UserId then following error displayed at the time of update or delete a record

"Conversion failed when converting the varchar value 'FI' to data type int."

and i have changed the data type of useris to varchar also.
plz help me sir

Suresh Dasari said...

@Rajeev Ranjan...
That problem because of you mentioned column datatype as int and sending string values to that column. i think you forgot to change your stored procedure datatype int to varchar check it once...

RAJEEV RANJAN said...

sir i have created a table like this
carete table cat1(
category_code varchar(10),
category_name varchar(50),
category_short_desc varchar
)

insert into cate values('FI','Fitness','fitness')
insert into cate values('IN','Indoor Sports','Sports')

i have aply DataKeyName in category_code column

here is code for delete the record
protected void gvDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string code = Convert.ToString(gvDetails.DataKeys[e.RowIndex].Value.ToString());
con.Open();
SqlCommand cmd = new SqlCommand("delete from cat1 where category_code=" + code, con);
int result = cmd.ExecuteNonQuery();
con.Close();
if (result == 1)
{
BindEmployeeDetails();
lblresult.ForeColor = Color.Red;
lblresult.Text = " details deleted successfully";
}
}

and the same error found at the the time of update the table ..pls help me sir

RAJEEV RANJAN said...

i have solved my problem sir ..
thank you so much.

sir is there a sample for live search from database in asp

Suresh Dasari said...

@Rajeev Ranjan...
Check this article http://www.aspdotnet-suresh.com/2011/12/search-records-in-gridview-and.html

RAJEEV RANJAN said...

it is nice but i want live search like facebook search box.

RAJEEV RANJAN said...

sir
how can i display only one row which is click for edit..bcoz the grid view of my database is so long and when i press edit for last row it wil disply in edit mode but the page will move to up so we scroll down the page where i choose for edit the row

anee said...

this is working very fastly but i have one problm whne grid contains much record then it get scrolled ,i want that footer is going to be fixed.
so how to fix the footer in above grid plz rly sir...its urgent

Suresh Dasari said...

@anee....
Check this link here i explained scrollable gridview with fixed header same way you can implement for your footer
http://www.aspdotnet-suresh.com/2011/11/how-to-implement-scrollable-gridview.html

Anonymous said...

bit i want same above grid with edit ,delete.but add in footer row should be fixed.i don;t get help from link....plz rly soon

anee said...

but i want same above grid with edit ,delete.but add in footer row should be fixed.i don;t get help from link....plz rly soon

SANTHOSH said...

Hello Suresh,

Registration with Facebook Id in my application..

So need some help

Anonymous said...

hey,
wen i enter data in the o/p that data store in the table using update query..... how can i solve???give me code....

Antony Francis said...

Hi,
your coding is very useful. I made some modification in the above coding I feel one difficulty. That is I added a button or a dropdownlist with autopostback set as true. Initially the gridview is empty and thus "No Records Found" message is shown. When I select any item from the dropdownlist or button click an empty row with Item Template controls(edit and delete) at 1st row position by the gridview.
please give me a solution for avoiding this auto post back problem.
Thank you...

Anonymous said...

very - very useful sir,

Santhosha H.P said...
This comment has been removed by the author.
Shimla Choudhary said...

really it's helpful for me

Anonymous said...

Awesome

Salman Rehman said...

anusha check the code using break point "Step Into"..

vamsikrishna said...

vamsi krishna

Anonymous said...

thanks a lot

iQm abk said...

this is a very good site I've come across,
Thank you Suresh

iQm abk said...

Wow! just posting the comment gives user google account details and link to user blog to the website. This is wonderful. How did you do this? How can I achieve this in my website? I am new to asp.net and programmer in C#. Moreover there is sign out option too. Does that make user sign out of google?

Anonymous said...

crore of thanks to you sir...

ashok kumar Thella said...

Suresh garu your examples are soooo good, i have a small doubt,if there is in(sql data base) no of particles like name ,date, dob etc. so, my requirement is ,i need two of them only. Is it possible in Grid view. Please Post Your answer.

Anonymous said...

while implementing this code m getng error as server is not tagged well....?help me

Manjunathan Mani said...

HI i am manjunathan I want insert,delete,update,edit,searching with gridview coding can u any one help me pls
in designing part i want to use query

neeraj kanojiya said...

hey suresh..
Gud job man. Really helpful form me..
Thanks for sharing

Anonymous said...

Thank You Suresh

Anonymous said...

Thanks Boss Its Really Helpfull...May God Bless u....

anas said...

sir,
i am getting this error when i am compiling this code
"The name 'color' does not exist in the current context "
can you help me out

nisha said...

nice website...

anas said...

sir ,
help me out i am waiting for your reply
i am new to .net is there any other post in which simple insert update delete operation is performed?

Suresh Dasari said...

@anas,
i hope u forgot to add namespaces mentioned (using system.drawing) in post. Please check it once...

kunal pargat said...

input string is not currect formet error occure during update and deleting .....what is the solutin..........please tell me

Prem Arya said...

Thanks it helps me lot keep on such nice work

anas said...

sir,
it worked out ... thnx-:)

Anonymous said...

Hi suresh,


I am satyam . Can you tell me how to access like button of Facebook to my website by using WCF and please provide the code for this

Anonymous said...

hi i need help. when start w/o debugging i have this error
Invalid object name 'Employee_Details'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'Employee_Details'.

Source Error:


Line 32: SqlDataAdapter da = new SqlDataAdapter(cmd);
Line 33: DataSet ds = new DataSet();
Line 34: da.Fill(ds);
Line 35: con.Close();
Line 36: if (ds.Tables[0].Rows.Count > 0)


here is my code :

public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection("Data Source=SIN-L-RLIM\\SQLEXPRESS;Integrated Security=True;Initial Catalog=EmployeeDB");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindEmployeeDetails();
}
}

protected void BindEmployeeDetails()
{

con.Open();
SqlCommand cmd = new SqlCommand("Select * from Employee_Details", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count > 0)

Anonymous said...

Suresh, I'm not an ASP developer, but was able to put an ASPX page together some time ago that does just this that you showed. It runs smoothly when under VS IDE, but when I deploy it to GoDaddy's server, it pops the following error :

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

I'm willing to pay for you to correct this and leave this page running fast when deployed. My e-mail is epastorejr(arr)hotmail(dot)com, please get in touch. Regards, Emilio.

afsal said...

hi.. could you please give the code in vb.net

Yogesh Boraste said...

IMAGES edit/delete continously refresh after insert ing one record so its little bit disturbing please
tell me solution i used update panel but does not work another point i want enter instead of tab about navigation

Dipak said...

Dear Sir,

I want to make a DLL which recive some information and errors from another application and display it on text file named error.txt
scenerio
------------------------------------------------
Some Information Processed and displayed





------------------------------------------------
Repeat this step Each time client Application Call this DLL

Anonymous said...

hi suresh, how r u? whats ur contact no........
plz send ur no. on my emailID.my emailID is mantosh05@gmail.com

raj kumar said...

Hi suresh,

I have one big dought. i think u solve this problem.

I have one gridview, in grid one dropdown list, dropdown list have values after that last one control, when u click the control one popup will be show.

How to solve this problem.
Please try to this problem every one.
please share with me.

My mail id:- rajkumarse6@gmail.com

Anonymous said...

i am raju i want to know about how to image update in gridview. please help me

Virtual Web Solutions said...

Thanks for a really nice article.
I really enjoyed it.

Many Thanks.

Jatin said...

This is the best... gr8 ..nice job done and very helpful for our .net juniors,hope every juniors will like this post.

Thnks & Regards,
Jatin Kashwani

Anonymous said...

thank you very much giving good example. keep posting. http://murraliitechnos.in

Anonymous said...

very helpful article. Thank you so much.. Keep writing this kind of article

Anonymous said...

it's very helpful.
thnx.....

ravi singh said...

how delete row in datagridview
plz sir
code send ravisin562@gmail.com

Retty said...

thanku very much............... you helped me a lot.............

shanti said...

its very help ful... thank you

Anonymous said...

amazing work.. wish u gud luck..

Anonymous said...

Really helpful for me

Mian Zaid said...

Dear Suresh,

Very good effort and I really appreciate your hard work. Thanks!

Zaid Ahmad
Software Engineer
Lahore(Pakistan).

Anonymous said...

nice

Bhaskar Paranjape said...

such nice and gr8 guidance

Anonymous said...

hai

Anonymous said...

I am beginner,its very helpful for me
Thank You Suresh...

Anonymous said...

sir iam fresher ,ple help me to how learn qick in .net,show me simple ways.

Anonymous said...

fabulous job suresh..

Sathish Ramamurthi said...

i have error from edit to update,delete button

Anonymous said...

Really u are an n genious ,
just i go stuck with UserId , but now the grid working charm ...
Really superb,,

thans

Shiva Reddy said...

i want code for text box not allowing special characters i have a code but not work in firefox

Rahul said...

How to display message Box while deleting Items from grid view.

Rahul said...

dear Suresh,

Please tell how to write above example i.e edit update and delete using three layers ?
i.e presentation layer business object and data access layer please clear above example

akhilesh mishra said...

A1

Anonymous said...

very nice post ..

Anonymous said...

really awesome,
keep writing tutorials like this...
thanks...

neeraj said...

thanks

neeraj yadav azamgarh said...

very good

aparna said...

Hi suresh i have 1 doubt..
after clicking edit button it goes to update nd cancel. right. how it possible ??
plz replay me

sam said...

it is not working in allowpaging true.............

Anonymous said...

sir, its really working.. thank u so much..

Anonymous said...

sir, am divya...its a best way to insert, update and delete the data to the table. this post really helps me a lot.. thank you sir..

but if are using this for master table means we cant able to delete the data..
for that can i use some flags?? how to use flags here?? can u suggest me??
plz...

help me sir..


Anonymous said...

sir, i need how to insert, delete, update and cancel in details view in codeing

Nikhil Goplani said...

thanks is very helpfull

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Amol Dhadve said...

HI .............thnx for code.......
but footr template for add is not visible at runtime

Amol Dhadve said...

is there problem in following code:::


Amol Dhadve said...
This comment has been removed by the author.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

Please anyone can explain What is the use Eval function in the above code , also i want to know how to use it and when to use it ?

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Rotem Refael said...

hi, why is the gvDetailes in default.cs is not recognize?

Gargi said...

I don't know sir ,if you are still replying at this site as your last reply was at Oct 6,2012. Still if you can assist please help,i couldnt find ts solution even at google,and other places still.and am a beginner in asp.net. am getting this following error,how should i remove this?
"Validation(XHTML 1.0 Transitional):Element 'panel' is not supported."

rahul tomer said...

This is awesome..

raja pandurangan said...

help me to learn the insert delete and update the data in asp.net c# with two textbox...

i went an interview their they are asking to do a task by saving the data and retrieving the edit delete and update... i m begineer pls help me to learn this... my mailid rajarockz666@gmail.com

raja pandurangan said...

also tell me where will u post the answer

Anonymous said...

Nice article . Learned many things from this post & about GV .

One doubt , is it needs to give "onrowcommand="gvDetails_RowCommand"" in .aspx page ? If we place this , Rowcommand method executes twice .

Ramaraj said...

Its working gud Mr.Suresh. wil u pls giv this in 3-tier architecture

Anonymous said...

Mr. Suresh
In My DB... 4 tablse
1) Registration table
2) Country table
3) state table
4)city table

Now in registration table many colums like name ,Mobile,Country, state, city,...etc

and i want to fetch data of Country, state and city from those tables (Country,State and City)

and I also want to save them into Registartion Table also So can in Possible..?
Give me answer.... pls

Anonymous said...

thnx you sir for giving best solution

Yogesh Koshti said...

thnx you sir for giving best solution....this is one of the best site for IT

Jason Rivera said...

I am having trouble whle following this example. I have a dropdownlist that populates with the column names of the table and a text box. I sucessfully search for records that only match the type input and rebind with no issues. Now if I try to use the edit or delete buttons the page crashes with the error:

Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

all my research points to the IsPostback but if that were the case my postback from my search field wouldn't work either. Help

Jason Rivera said...

changed the buttons from Image buttons to Link buttons and that works, however there is one more issue. I set the CommandName on the AddNew button and I enter the new data in the footer, but upon stepping through the code I see that the fields being returned is "{System.Web.UI.WebControls.TextBox}", not sure what I missed. I even tried just storing them in a string variable, no luck.

Anonymous said...

@Sam


for using allow paging, set the following properties in gridview,

AllowPaging ="true" PageSize ="3" OnPageIndexChanging="gvDetails_PageIndexChanging"


and also add the following code,


protected void gvDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

gvDetails.PageIndex = e.NewPageIndex;

BindEmployeeDetails();

}

hope this will help you..

regards
divya..

Rotem Refael said...

hi, thankyou for this post. i have a problem- nothing is happening when i am clicking the images (delete, update, insert)

need your help asap!

Sesu Raj said...

Dear suresh could you upload the the code for merge gridview headers in asp.net.? Please kindly help me

Anonymous said...

It helps a lot... good post suresh...I'm proud that you are an andhra guy...

Manju T said...

realy awsome man keep in touch for clear my doubts

Anonymous said...

how to use dublict value in your gridview
thans..

Anonymous said...

Why you not record this things Its better way to explain and easy to understand

rajesh k said...

This is very useful to me !

Thank U Very much

Anonymous said...

good one

Anonymous said...

Hi,
i want to perform update,delete and insert options using MVC 4,after performing the operations it should be displayed in gridview and should be updated in the database,how can i do that,please let me know i need it ASAP...
any help would be appreciated..
Thankyou so much,
Bhavani.

Anonymous said...

please help me ,its really important...
thankyou,
Bhavani

Bharath said...

Asp.net insert, Edit, update, delete data in gridview

Hi sir this is bharath, i am doing the above ur example. i am getting an error in RowUpdating event.
"system.web.ui.webcontrols.gridviewupdateeventargs does not contain a definition Rowindex"

colud u plz help me...

Anonymous said...

Hi Avneesh here i m getting an error in update section "Object reference not set to an instance of an object".

Plz help me out Thx in advance.....

MONICA G said...

I want to insert,update ,delete,in gridview. But Here only we can bind the data,, but i need images also to be binded in gridview with the help of fileupload control.Inside the footer template only i need fileupload control to be accessed..

Anonymous said...

Thank you sir, Nice material

Anonymous said...

I HAVE ONLY FEW WORDS FOR YOU........

"GOD BLESS YOU"

Krishna Kumar said...

hello suresh..can you give me calculator source...please.i have made but it complex..
Sorce code of calculator.
d

Niresh Kumar said...

very nice article...super....

Niresh Kumar said...

i need a help for this...i have 3 radio buttons in gridview...how can i update data using radio buttons...without radio button thats not a problem...using radio buttons how can i update data in asp.net with c#

sindhu said...

sir, suppose there are 2 pages and on click of some hyperlink the control goes to next page.

in the next page i'm inserting some data and once i click the submit button, the details are stored in the database and immediately the control should go to the 1st page... not knowing how to go about it.

please help me sir.

john cena said...

its simply superb........

Anonymous said...

Hi Suresh,

Thanks for the fantastic article. It is very useful. You have explained everything so simply that I have got no questions regarding the topic but I have another question for you.

How did you create the GIF image to show demo ?
Which software did you use ?


Regards,
Maulin Thaker

Anonymous said...

I want to insert,update ,delete,in gridview. But Here only we can bind the data,, but i need images also to be binded in gridview with the help of fileupload control.Inside the footer template only i need fileupload control to be accessed.. Please can u help me... Thank you...

Anonymous said...

thanks

Anonymous said...

Nice Program......

Anonymous said...

Very nice article. Fully working...thanks.

Anonymous said...

nice and simple programs for fresher like me it was hard to think about simple program.
but u made it easy understanding and for practice too.

thanku

Mukul Sharma said...

hello sir,
there is problem in binding of gridview with empty data. if i use your code and there is no data in table then EDIT and DELETE botton automatically appears and create problem if i click on that buttons.
Is there any code so that i can hide those buttons an can display only empty Griedview.

Mukul Sharma said...

sir
pllease help me its urgent for me.

Paritosh Kadam said...

Sir,
I have tried it in entity framework too but it didn't work for me.
problem is when gridview is empty at that time gridview not showing the footer.
And using entity framework how to show the no record found msg in gridview?

Welcome to said...

Hi Sir,

How to insert the Current Date and time into Gridview from Textbox and save it into SqlServer 2008 and display the current date time into gridview.

Tanmoy said...

Thanks...!!! Simple one yet fantastic...!!!

Anonymous said...

Sir,
I hav a question that whether jquery is required for that or whatever you hav written that is sufficient

Anonymous said...

it is good one..

vicky said...

I am fresher. I am doing one small medical application which has around 29 fields in database.. I want to use a grid view, only for few fields.. Is it possible? If yes, then how to do... Database is oracle 10g.

Waiting for your reply

kazi sohel said...

hi sir,
I want code for search box to put on website

Anonymous said...

reference object set an instance is not nulled i got this error

Anonymous said...

Thanks For Giving Great Examples For Leanrners

Balu Andhale said...

Thanks Sir...............

Anonymous said...

each n every thing is exlained clearly thanq....very helpful for freshers....:) :)

Vishal said...

Create a employee table, designation table, as soon as we select designation form dropdown list according to that the employee name should be display in grid view. The grid should be fully editable all facilities should be there.
Take 5 designation names in table.
Use stored procedure.

Does anyone have a solution? Please help me.

Kanti Khairaliya said...

suresh i have 2 or more gridview on page
when i use your code on first gridview its work fine but when i use same code on second gridview the both are not working

Arshmeet Singh said...

its great

Anonymous said...

very simple and very worthy

Admin said...

Hello Suresh
I use your post for development but now days demo images are not visible on site. The demo images are very useful to me.

nilu gupta said...

sir this code is very effective .. but some problem occur..

TextBox txtR_adderss = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtR_adderss");
in this line :-e.RowIndex gives error .. so pl if possible beacouse it does not contayins in the cureent contecst on update and add new button. thak u pl ... sir

Anonymous said...

thnx

sivas kangalı said...

thanks for your sharing.

Sinis said...

hello sir thank you for your guidance...but im facing a problem when trying to update..im beginner in this kind of arrangment....can you tell me why this happen?...

Object reference not set to an instance of an object.<----- happen when update button is clicked..search at google failed to find any solution.

Anonymous said...

Hi suresh error on deleting data "Index was out of range. Must be non-negative and less than the size of the collection."

Anonymous said...

hello sir,
I'm kohila. your each and every code run successfully.
but, in my project i have to save gridview data and other textbox data at the same time,
in a single table.
please give me sample code for these. please do it for me sir.
i hope many people get useful if you post that code.
thank you sir.
here my email-id: kohilavani2011@gmail.com.
Thank you sir.

Anonymous said...

only insert is working.. foe deleting and updating i'm getting an error like input string was not in correct format.. can u help?

Anonymous said...

earn online register there ,,,,, http://www.Pay4Visits.com/index.php?refcode=7640

gjayaprakash said...

"system.web.ui.webcontrols.gridviewupdateeventargs does not contain a definition Rowindex"

infoline said...

very nice website man ,,,,,,K.$..

Anonymous said...

A1 site

SuneelKumar Amujuri said...

Good Evening sir,
thank u for the code, but i'm getting an error while changing the auto-generate columns property to false give me some guidance to solve this problem......

Nazim Mansoori said...

Hello Suresh ,
I have a question i wanna use gridview for only inserting the records but without binding the data in gridview it is not appearing. can u help me out

«Oldest ‹Older   1 – 200 of 231   Newer› Newest»

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.