Introduction:
In this article I will explain how to insert, edit, update and delete data in gridview using asp.net.
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
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. |
|||
|
|||
252 comments :
«Oldest ‹Older 1 – 200 of 252 Newer› Newest»Good one it helped a lot
hey really awesome..can i ve ur number..i feel vry proud to ve ur number in my mobile..awesome dude..keep helping..
Can i know the explanation of each of the tag used in above example..
Thanks Boss, this is best site for IT Languages and database.
Good start suresh...Your articles are excellent!!!! Great stuff...
really helpfull.Its working quit faster.
thanx for sharing
excellent one but while deleting a record the confirmation is not cumming which is written using JavaScript function
Can you give your number please
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
i can't understand how to insert,update and delete in gridview .please explain briefly.
gud mrng sir,i want this as in 3-tier.please explain sir
thanx ... its a relaay nice post
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.
i got problem in con.open() plz help me my mind is gng to blast...plzzzzzzz help me soon...
very useful..
Excellent! It was so good I'm now using it! Thank you for sharing!
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!
best one sir really very helpfull sir.
And thanks for sharing
God bless you.
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
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"
Can i include an imageicon in the gridview columns
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
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.
Thanks,Was confusing before this one but now clear as i was did this earlier but through direct DSN.
Issac.
Very very Thanks suresh . freshers or exp helpfull to this website
Im facing error like this:::(Object reference not set to an instance of an object.)plz help me sir.
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
hhkjhjk
Gracias, muy bueno.
i don have any words bro. u are a DOTNET-GOD
really nice work
only insert in working...when click delete it will go to row command..pls help me out
anyone pls help me..
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();
}
pls help me my above code is not working properly in while deleting
@Anusha...
Pls check whether you gave CommandName="Delete" for your delete button or not.
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......
good yar excelent...........
vamsi
------
error
------
Object reference not set to an instance of an object
soluction
---------
once check web.config page
I am always preferring you site only boss....
Hi,
A very helpful post.. It was really easy to understand.. Thanks a lot..:)
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
@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...
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
i have solved my problem sir ..
thank you so much.
sir is there a sample for live search from database in asp
@Rajeev Ranjan...
Check this article http://www.aspdotnet-suresh.com/2011/12/search-records-in-gridview-and.html
it is nice but i want live search like facebook search box.
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
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
@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
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
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
Hello Suresh,
Registration with Facebook Id in my application..
So need some help
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....
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...
very - very useful sir,
really it's helpful for me
Awesome
anusha check the code using break point "Step Into"..
vamsi krishna
thanks a lot
this is a very good site I've come across,
Thank you Suresh
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?
crore of thanks to you sir...
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.
while implementing this code m getng error as server is not tagged well....?help me
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
Thank You Suresh
Thanks Boss Its Really Helpfull...May God Bless u....
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
nice website...
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?
@anas,
i hope u forgot to add namespaces mentioned (using system.drawing) in post. Please check it once...
input string is not currect formet error occure during update and deleting .....what is the solutin..........please tell me
Thanks it helps me lot keep on such nice work
sir,
it worked out ... thnx-:)
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
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)
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.
hi.. could you please give the code in vb.net
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
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
hi suresh, how r u? whats ur contact no........
plz send ur no. on my emailID.my emailID is mantosh05@gmail.com
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
i am raju i want to know about how to image update in gridview. please help me
Thanks for a really nice article.
I really enjoyed it.
Many Thanks.
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
thank you very much giving good example. keep posting. http://murraliitechnos.in
very helpful article. Thank you so much.. Keep writing this kind of article
it's very helpful.
thnx.....
how delete row in datagridview
plz sir
code send ravisin562@gmail.com
thanku very much............... you helped me a lot.............
its very help ful... thank you
amazing work.. wish u gud luck..
Really helpful for me
Dear Suresh,
Very good effort and I really appreciate your hard work. Thanks!
Zaid Ahmad
Software Engineer
Lahore(Pakistan).
nice
such nice and gr8 guidance
hai
I am beginner,its very helpful for me
Thank You Suresh...
sir iam fresher ,ple help me to how learn qick in .net,show me simple ways.
fabulous job suresh..
i have error from edit to update,delete button
Really u are an n genious ,
just i go stuck with UserId , but now the grid working charm ...
Really superb,,
thans
i want code for text box not allowing special characters i have a code but not work in firefox
How to display message Box while deleting Items from grid view.
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
very nice post ..
really awesome,
keep writing tutorials like this...
thanks...
thanks
Hi suresh i have 1 doubt..
after clicking edit button it goes to update nd cancel. right. how it possible ??
plz replay me
it is not working in allowpaging true.............
sir, its really working.. thank u so much..
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..
sir, i need how to insert, delete, update and cancel in details view in codeing
thanks is very helpfull
HI .............thnx for code.......
but footr template for add is not visible at runtime
is there problem in following code:::
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 ?
hi, why is the gvDetailes in default.cs is not recognize?
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."
This is awesome..
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
also tell me where will u post the answer
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 .
Its working gud Mr.Suresh. wil u pls giv this in 3-tier architecture
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
thnx you sir for giving best solution
thnx you sir for giving best solution....this is one of the best site for IT
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
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.
@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..
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!
Dear suresh could you upload the the code for merge gridview headers in asp.net.? Please kindly help me
It helps a lot... good post suresh...I'm proud that you are an andhra guy...
realy awsome man keep in touch for clear my doubts
how to use dublict value in your gridview
thans..
Why you not record this things Its better way to explain and easy to understand
This is very useful to me !
Thank U Very much
good one
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.
please help me ,its really important...
thankyou,
Bhavani
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...
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.....
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..
Thank you sir, Nice material
I HAVE ONLY FEW WORDS FOR YOU........
"GOD BLESS YOU"
very nice article...super....
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#
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.
its simply superb........
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
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...
Nice Program......
Very nice article. Fully working...thanks.
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
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.
sir
pllease help me its urgent for me.
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?
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.
Thanks...!!! Simple one yet fantastic...!!!
Sir,
I hav a question that whether jquery is required for that or whatever you hav written that is sufficient
it is good one..
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
hi sir,
I want code for search box to put on website
reference object set an instance is not nulled i got this error
Thanks For Giving Great Examples For Leanrners
Thanks Sir...............
each n every thing is exlained clearly thanq....very helpful for freshers....:) :)
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.
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
its great
very simple and very worthy
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.
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
thanks for your sharing.
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.
Hi suresh error on deleting data "Index was out of range. Must be non-negative and less than the size of the collection."
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.
only insert is working.. foe deleting and updating i'm getting an error like input string was not in correct format.. can u help?
earn online register there ,,,,, http://www.Pay4Visits.com/index.php?refcode=7640
"system.web.ui.webcontrols.gridviewupdateeventargs does not contain a definition Rowindex"
very nice website man ,,,,,,K.$..
A1 site
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......
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
hi suresh in this articles user id cant displayed in the output. only username, city and designation only available in the gridview during the running section so pls tel me how solve this... mail to ksanbutnj@gmail.com
thank u sir
Hello sir,
Can we use the above function dynamically for all tables??
Sir I have done the same coding but while updating event execution the code is taking old values of template textbox. Please help me on this issue. This is my update event code....
TextBox EName, MobileNo, Address;
Label Eid;
GridViewRow grv = (GridViewRow)GridView2.Rows[e.RowIndex];
Eid = (Label)GridView2.Rows[e.RowIndex].FindControl("Label6");
EName = (TextBox)GridView2.Rows[e.RowIndex].FindControl("TextBox15");
MobileNo = (TextBox)GridView2.Rows[e.RowIndex].FindControl("TextBox17");
Address = (TextBox)GridView2.Rows[e.RowIndex].FindControl("TextBox19");
UpdateData(Eid.Text, EName.Text, MobileNo.Text, Address.Text);
GridView2.EditIndex = -1;
thanks sir...........
i used your code it worked fine....but am facing prob that when i click edit the rowcells which are not in edit mode are shrinking.....any solution??
Note: Only a member of this blog may post a comment.