GridView insert update delete in asp.net - Part 23

Поділитися
Вставка
  • Опубліковано 8 лют 2025
  • Link for csharp, asp.net, ado.net, dotnet basics and sql server video tutorial playlists
    / kudvenkat
    Link for text version of this video
    csharp-video-tu...
    Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our UA-cam channel. Hope you can help.
    / @aarvikitchen5572
    In this video we will discuss about performing an insert, update and delete on asp.net gridview control using sqldatasource. We will be using tblEmployee table for this demo. SQL script to create and populate this table with sample data is available in Part 13 of asp.net gridview tutorial.
    Create an asp.net web application. Drag and drop a gridview and a sqldatasource control on WebForm1.aspx.
    Configure "SqlDataSource1" control
    1. Right click on "SqlDataSource1" control and select "Show Smart Tag"
    2. Now click on "Configure Data Source" link
    3. Select connection string, from the dropdownlist on "Choose your data connection" screen. You need to have a connection string specified in web.config file.
    4. Click Next
    5. On "Configure the Select Statement" screen, select "tblEmployee" table from dropdownlist.
    6. Click on "Advanced" button
    7. Select "Generate INSERT, UPDATE and DELETE statements" checkbox and click OK
    8. Click Next and Finish
    Drag and drop gridview control on WebForm1.aspx. Now let us associate "SqlDataSource1" control with "GridView1" control
    1. Right click on "GridView1" control and select "Show Smart Tag"
    2. Select "SqlDataSource1" from "Choose Data Source" dropdownlist
    3. Select "Enable Deleting" and "Enable Editing" checkboxes. At this point "Delete" and "Edit" buttons should appear on the gridview control.
    We will be using gridview control's footer for inserting a new record. Set "ShowFooter" property of the GridView1 control to "true". This can be done from the properties window, or in the HTML.
    By default GridView control has generated bound fields to display EmployeeId, Name, Gender and City columns.
    We need to convert these bound fields into template fields. This can be done very easily using the designer.
    1. On the "GridView Tasks" pane click on "Edit Columns" link button.
    2. Select "EmployeeId" from "Selected Fields" section and click on "Convert this field into a template field" link
    3. Do the same for Name, Gender and City
    Now modify the template fields in the HTML. Please note
    1. In every TemplateField, along with EditItemTemplate and ItemTemplate, we also need FooterTemplate.
    2. A dropdownlist is used in EditItemTemplate and FooterTemplate of "Gender" template field, instead of a textbox control.
    3. To validate data during edit and insert operations, notice that, we are using validation controls, in EditItemTemplate and FooterTemplate.
    4. A linkbutton is used in the footer template of "EmployeeId" template field, to enable the user to insert a new employee row
    5. We have used ValidationGroup="Insert" for all the validation controls in FooterTemplates. LinkButton's ValidationGroup is aslo set to "Insert", so that all the validation controls in in FooterTemplates are fired only on Insert LinkButton click.
    6. We have set LinkButton's OnClick="lbInsert_Click".
    7. After the closing tag of GridView, notice that we are using 2 validationsummary controls, to display all the validation messages in one place. ValidationSummary1 control's ValidationGroup is set to "Insert". ValidationSummary1 control displays all insert related validation errors, and edit related validation errors are displayed using ValidationSummary2 control.
    Finally copy and paste the following event handler method in WebForm1.aspx.cs
    protected void lbInsert_Click(object sender, EventArgs e)
    {
    SqlDataSource1.InsertParameters["Name"].DefaultValue =
    ((TextBox)GridView1.FooterRow.FindControl("txtName")).Text;
    SqlDataSource1.InsertParameters["Gender"].DefaultValue =
    ((DropDownList)GridView1.FooterRow.FindControl("ddlGender")).SelectedValue;
    SqlDataSource1.InsertParameters["City"].DefaultValue =
    ((TextBox)GridView1.FooterRow.FindControl("txtCity")).Text;
    SqlDataSource1.Insert();
    }

КОМЕНТАРІ • 267

  • @mcfawknuts
    @mcfawknuts 9 років тому +5

    Thank you soooo much for this!

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  9 років тому +5

      +mcfawknuts Thanks a lot for stopping by to provide your feedback. This means a lot to me. I am really glad you found the video tuorials useful.
      All the Pragim Tech video tutorials are organised in to playlists, which help you find the videos you are looking for easily
      ua-cam.com/users/kudvenkatplaylists?view=1&sort=dd
      You can also order DVDs or download all the videos and slides for offline viewing using the link below
      www.pragimtech.com/kudvenkat_dvd.aspx
      Image version of the slides and text Version of the videos are on my blog
      csharp-video-tutorials.blogspot.com
      Tips to effectively use our free channel.
      ua-cam.com/video/y780MwhY70s/v-deo.html
      To receive email alerts, when new videos are uploaded, please subscribe to my youtube channel.
      ua-cam.com/users/kudvenkat
      If you like these videos, please click the THUMBS UP button below the video.
      We like to see these free video tutorials helping others as well. Please share the link with your friends and family who you think would also benefit from them.
      Thanks
      Venkat

    • @somanapallilokkeshwararav7043
      @somanapallilokkeshwararav7043 4 роки тому

      Worsted

  • @stephanieezat-panah7750
    @stephanieezat-panah7750 6 років тому +2

    I had some problems with the Insert function not working. I believe that it had to do with not using a "protected" access modifier. it works now. And, thank you, Professor Venkat. You are the best, simply the best. I have watched all your videos: C#, asp.net, ado.net and SQL Server. My career has been enhanced & enabled. I cannot thank you, enough.

  • @nikhillala1451
    @nikhillala1451 7 років тому

    This was literally the easiest and the most efficient method anyone could have ever implemented. Thank you for sharing this with us. Helped Alot!

  • @kalin1993
    @kalin1993 6 років тому

    You are a hero. My course project was finished because of your guide.Thank you very much.

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  6 років тому

      Hearty congratulations on successful completion of your course project. Very glad the videos helped. Thank you very much for taking the time to give feedback. All the very best with everything you do.

  • @WolfgangLettko
    @WolfgangLettko 9 років тому +5

    Your videos are very helpful ! Most i know from ASP.NET i have learned in your videos. Great work ! Thank you.

  • @Csharp-video-tutorialsBlogspot
    @Csharp-video-tutorialsBlogspot  11 років тому

    Thank you very much for taking time to give feedback. For email alerts, when new videos are uploaded, please subscribe to my channel. In the description of this video, I have included the link for ASP .NET, C#, and SQL Server playlists. All the videos are arranged in logical sequence in these playlists, which could be useful to you. Please share the link with your friends who you think would also benefit from them. If you like these videos, please click on the THUMBS UP button below the video.

  • @mryoso22
    @mryoso22 7 років тому

    this is so useful man! you've just upgraded humanity in a whole new different level.. hope i could see you in person.. (im serious, im your number 1 fan)

  • @Tlgte
    @Tlgte 5 років тому

    Even though this video came out in 2013, it still came in very useful for finishing my assignment. Thank you.

  • @lopintipriya3510
    @lopintipriya3510 11 років тому

    hello venkat, Thank you very much.i understood and i could implement according my requirement .without ignoring it as a silly question, you answered so well, i truly admire your help.Thank you once again

  • @arunaravind571
    @arunaravind571 8 років тому

    Thank you so much sir.....Best asp.net video I had ever seen...Hats of your effort..thank you so much.

  • @Csharp-video-tutorialsBlogspot
    @Csharp-video-tutorialsBlogspot  11 років тому

    To receive email alerts, when new videos are uploaded, please subscribe to my youtube channel. May I ask you for a favour. I want these tutorials to be helpful for as many people as possible. Please share the link with your friends and family who you think would also benefit from them. If you like these videos, please click on the THUMBS UP button below the video.

  • @johnsongeorge5906
    @johnsongeorge5906 8 років тому

    Best tutorial on UA-cam Ever Million time Thanks Sir GOD BLESS you.....!

  • @Csharp-video-tutorialsBlogspot
    @Csharp-video-tutorialsBlogspot  11 років тому

    Hi Sujatha, sure, will record and upload a video on this soon. In the description of this video, I have included the link for ASP .NET, C#, and SQL Server playlists. All the videos are arranged in logical sequence in these playlists, which could be useful to you. Please share the link with your friends. If you like these videos, please click on the THUMBS UP button below the video. For email alerts, when new videos are uploaded, you may subscribe to my channel.

  • @charlesrabelloable
    @charlesrabelloable 9 років тому +2

    This videos was great, very helpful to my projects. Sharing knowlodge turn the world better. So, I will do the same sharing what I learned with brazilian folks in portuguese. Thanks, and keep sharing.

  • @TheSplifydadz
    @TheSplifydadz 10 років тому

    Keep up the good work kudvenkat, we really appreciate it. Thanks.

  • @JoeG2324
    @JoeG2324 11 років тому +5

    amazing video. best asp .net tutorial series on youtube.

  • @Csharp-video-tutorialsBlogspot
    @Csharp-video-tutorialsBlogspot  11 років тому

    "SelectedIndexChanged" is the default event of GridView control. It is very easy to identify default events of controls in asp.net. Drag and drop a control on the webform, double click on the control, and an event handler method will be generated in the code-behind file automatically for the default event. Hope, you will find this useful. If you like these videos, please click on the THUMBS UP button below the video. Good Luck.

  • @pqmg
    @pqmg 8 років тому +1

    Absolutely great stuff! Thank you Kudvenkat for sharing this! :)

  • @Ayubajbnabi
    @Ayubajbnabi 12 років тому

    Excellent. Thank you very much Kudvenkat.

  • @mittalpatel4990
    @mittalpatel4990 11 років тому

    Can you please help to just submit record into database using ASP.net.
    You are really life saver. I am working almost 5 day to do connection string but your video are simply best.
    many many thanks

  • @shreya5235
    @shreya5235 3 роки тому

    Thank you. Your tutorials are very helpful.

  • @entemolu1
    @entemolu1 10 років тому

    No doubt, You are a Master of Master

  • @Csharp-video-tutorialsBlogspot
    @Csharp-video-tutorialsBlogspot  11 років тому

    Hi Priya, Here the ID column is an identity column. When we insert a row, we don't have to provide a value for this column. It will be auto-incremented and inserted by sql server automatically. In reality, it is unusual to provide a value for ID field. But if your, project requirement is to provide the value for ID, then we can very easily achieve by including a TextBox next to the insert link button in footer template of ID column. Hope this answers your question.

  • @IrishReGGie
    @IrishReGGie 3 роки тому +1

    LEGEND FOR DOING THIS

  • @amroosman9934
    @amroosman9934 9 років тому +1

    Thank you Man you are simply Stunning.

  • @MoathResume
    @MoathResume 11 років тому

    Thank you for your reply Kudvenkat, I actually just redid it and worked, thanks a lot :)

  • @madihasabihkhan5841
    @madihasabihkhan5841 9 років тому +1

    Very clearly elaborate each steps.

  • @Csharp-video-tutorialsBlogspot
    @Csharp-video-tutorialsBlogspot  12 років тому

    Hi Vivek, are you talking about doing everything in code using RowCommand, without using datasource controls. If that's the case we will be discussing about it very soon. Please stay tuned.

  • @sharvaryrane1702
    @sharvaryrane1702 7 років тому

    best video for beginners... thank you so much... really useful👍

  • @Csharp-video-tutorialsBlogspot
    @Csharp-video-tutorialsBlogspot  11 років тому

    This is discussed in GridView tutorial. In the description of this video, I have included the link for ASP .NET, C#, and GridView playlists. Hope you will find these videos useful.

  • @lopintipriya3510
    @lopintipriya3510 11 років тому

    hi venkat , i'm very thankful for the support you are providing for your fellow developers, Iam extremely thanful to you , and here is my silly question , after seeing the video, ok , here you are giving a demo on insertion, i see that insert button is sitting in the id field , so do we insert the value for that , and if it is a primary key field , it gives an error, is it'nt ,may be its a very stupid question, i dont know,but please tellme how can i give thevalue for the first field

  • @saialuri9370
    @saialuri9370 7 років тому

    Thanks a lot for your video,I got some knowledge on Insert,Update and Delete in Gridview.

  • @mandardesai3841
    @mandardesai3841 12 років тому

    I saw many video the way you explain is very good I saw many other .net video such as lynda.com pluralsight or other but your video is simply great.I have one request for you plz record video on windows database deployment application.in short how can create software with product key and adding .net framework with that windows application which is easily installed another computer.

  • @MissNumnum
    @MissNumnum 8 років тому

    its really help me a lots! Much love and thank u!!!!!!!!!!

  • @黄桂兰-o7k
    @黄桂兰-o7k 7 років тому

    Thank you very much for this good teaching. I have learned a lot from this video.

  • @Csharp-video-tutorialsBlogspot
    @Csharp-video-tutorialsBlogspot  11 років тому

    Hi, Aniruddha, this is easy to fix. The issue is that, validation controls are performing validations on the client, and are not allowing the page to be posted back to the server, so the code in Image Button click can be executed. To fix this, set CausesValidation property of the Image Button to true. Hope this answers your question. If you like these videos, please click on the THUMBS UP button below the video. Please share these videos with your friends on Google pluas and facebook. Good Luck.

  • @husamhabbal1419
    @husamhabbal1419 5 років тому

    a very big Thank you, you deserve more

  • @davester32
    @davester32 10 років тому

    Thank you for all your videos !

  • @hakeraz
    @hakeraz 10 років тому +2

    Congratulations, this is a good tutorial

  • @ArsalHussain
    @ArsalHussain 7 років тому

    I Want A Really Fast Video Implementation For CRUD In ASP GridView For Quick Revision And This Helps Me. Very Nice Work. And Also Thank You!

  • @SanjeevSriramoju
    @SanjeevSriramoju 11 років тому

    best video....usefull for beginersss

  • @csandhya5289
    @csandhya5289 11 років тому

    Hi sir, your videos are really helping me a lot for preparing interviews.Thanku so much.and one of the interviewer asked ,what is the default event for a gridview control?can you please share me the anser.

  • @sawlehapathan249
    @sawlehapathan249 6 років тому

    Thank you for this tutorial...really helpful

  • @vidhikansara7103
    @vidhikansara7103 7 років тому

    So helpful video tutorial thank you so much it really helped

  • @Jimpeeterske
    @Jimpeeterske 10 років тому

    You helped me a lot ! awesome video !

  • @karenwilson1558
    @karenwilson1558 8 років тому

    Thanks! Glad it's still on line!

  • @gandolfiniL
    @gandolfiniL 6 років тому

    Thanks, very good, all work perfect!!!

  • @markharris2944
    @markharris2944 12 років тому

    I love the videos. I am new to all this stuff and it is great to see videos that step you through step by step. How would I show the footer of a gridview when there is no data in the gridview? I have a dropdown list box that will show the records of the selected item but when there are no records associated with the listed item, I cannot insert a record because there is no footer.

  • @mohamedjaffir9097
    @mohamedjaffir9097 8 років тому

    thank a lot..very very useful and works fine..briefly describe

  • @archanashet5
    @archanashet5 8 років тому

    Very nice and helpful video.
    Thank You so much :)

  • @duynm
    @duynm 11 років тому

    Thank you, i love your videos

  • @Qazafi4u
    @Qazafi4u 11 років тому

    Hi There
    Thanks for this wonderful project. Would that be possibility the insert row will appear at the top of the grid instead at the bottom of the grid. Can you please reply it is really urgent.
    Thanks
    Qazafi

  • @stefanskoda6841
    @stefanskoda6841 12 років тому

    amazing as usual :) Thanks Kudvenkat

  • @SuperMillone
    @SuperMillone 11 років тому

    I solved it. I changed the line relevant the checkbox in the eventhandler like this: SqlDataSource1.InsertParameters["is_admin"].DefaultValue =
    ((CheckBox)GridView1.FooterRow.FindControl("chkCredential")).Checked.ToString().ToLower();

  • @Csharp-video-tutorialsBlogspot
    @Csharp-video-tutorialsBlogspot  11 років тому

    Hi Priya, you are very welcome. May I ask you for a favour. I am receiving lot of questions everyday from our youtube users, and finding it extremely difficult to answer all the questions in time. I hope, you can help me answer a few questions for which you know the answer. This will help boost your confidence, and also help build your network on youtube.

  • @abdelhadiessaifi7339
    @abdelhadiessaifi7339 9 років тому +3

    Thank you very much bro, you re my best mentor

  • @ww1flyingace263
    @ww1flyingace263 5 років тому +1

    I was able to put the insert link in the first column (same column as edit/update). I think it looks nicer there. In case anyone was wondering if it could be done.

  • @indikamakawitage
    @indikamakawitage 11 років тому

    Good Tutorial,Thank you so much

  • @priya354783
    @priya354783 10 років тому

    Very usefull !! Thanks :)

  • @Unearthed13
    @Unearthed13 10 років тому +1

    EXCELLENT video ... thank you so much :D

  • @sajadadal4276
    @sajadadal4276 7 років тому

    شكرا لك اخي على هاذا الشرح

  • @pixelbeans
    @pixelbeans 10 років тому

    Thank you very much. Excellent.

  • @robertomancino5517
    @robertomancino5517 4 роки тому

    Thank you so much for the helpful video. Just a simple question. I would like to edit a row after a filtered GridView, is that possible?

  • @61Ritz
    @61Ritz 11 років тому

    thanx awsome tutorial

  • @eieichitsu9722
    @eieichitsu9722 11 років тому

    Thanks you so much, I like the way u teach, this video is very helpful for my assignments. Thanks....^_^

  • @SuperMillone
    @SuperMillone 11 років тому

    Very interesting Thank you for such good work. Actually I have replaced the dropdown with a checkbox and I cannot make it working. I would appreciate some hint about how to change the code in the lblInsert to use a checkbox.

  • @Csharp-video-tutorialsBlogspot
    @Csharp-video-tutorialsBlogspot  11 років тому

    I think this is already covered in gridview tutorial. Please check and let me know if you have found it.

  • @jitendrasharma757
    @jitendrasharma757 11 років тому

    good try for understand to other peoples.

  • @scarlettflitzpatrick8501
    @scarlettflitzpatrick8501 11 років тому

    Thanks..nice videos!

  • @piyasidey2117
    @piyasidey2117 8 років тому

    you are like God..

  • @Z3rY
    @Z3rY 11 років тому

    hey kud, thank you 4 ur vids, they are very helpful, i gotta question and, i was trying 2 edit the template for my gridveiw, i added a drop down list on 1 of the fields, but the drop down list uses an SQLDataSource cuz i need some values from another table, but instead of editing it deletes the record when i pess update

  • @JackFurtarelly
    @JackFurtarelly 9 років тому

    What should i do if i would have to put on the footer row a calendar ( for example for a datetime from database ); how can i write that on the insert_click event ?
    Thanks and thanks for ur lessons , its helpin me a lot :)

  • @ashishpasi1524
    @ashishpasi1524 10 років тому

    thanks very help full

  • @mhasimioglu8410
    @mhasimioglu8410 9 років тому +1

    Thank you very much :)

  • @SteeveBalla2006
    @SteeveBalla2006 7 років тому

    great video

  • @NicePaki
    @NicePaki 11 років тому

    Hi Venkat, Thanks for these amazing videos, which are very helpful for us.
    I would like to bind Drop Down List with a DataSource but when I click edit I get error similar to "indurnuguri1" mentioned in his post.

  • @Csharp-video-tutorialsBlogspot
    @Csharp-video-tutorialsBlogspot  11 років тому

    Hi Moath, RequiredFieldValidator should support ControlToVaildate attribute, irrespective of VS2010 or VS2012. I am not sure what's wrong at the moment. Can you please include the complete declaration of RequiredFieldValidator. Since angular brackets, cannot be pasted in the comment, use square brackets [ ] instead of angular brackets.

  • @iamsanjaygautam
    @iamsanjaygautam 11 років тому

    Thanx bro for
    help

  • @jac94
    @jac94 10 років тому +1

    Hi Kudvenkat, thanks for the video. I just want to know how to show the gridview footer when the dataSource is empty, I mean, inserting the first row, becuase the gridview i this case doesn't show any row.

  • @dungcnpmb02
    @dungcnpmb02 6 років тому

    thank you sooooo much !!!!!!

  • @maryemchaaba8082
    @maryemchaaba8082 8 років тому

    thank you very much

  • @kunaldedhia5502
    @kunaldedhia5502 10 років тому

    If I use the way you have showed then is there a way to show the insert linkbutton in the same column as of the Edit/Delete column?

  • @win66K
    @win66K 11 років тому

    Hi Venkat,
    I want to know how to insert records using first row of the gridview not with using footer.

  • @junadashraf7936
    @junadashraf7936 6 років тому

    are you using DataReader or DataAdapter to connect to your DataBase?

  • @haniabidi7305
    @haniabidi7305 9 років тому +1

    Sir could you please tell me how to achieve validation group in mvc as you did in this video. I did not find any appropriate article on web.

  • @HonzaMatejicek
    @HonzaMatejicek 11 років тому

    I have to say really good and useful videos.
    But I would like to ask you about DropDownList used in EditItemTemplate. I'm using VS2012 .Net Framework 4.5 and the SelectedValue is missing... Do you have some video about handling DropDownList with code behind?

  • @fula5
    @fula5 8 років тому

    Excellent (y)

  • @VivekKumar-bj9qy
    @VivekKumar-bj9qy 11 років тому

    Hi venkat, Thank for this such wonderful videos. I am having one problem. When i select value from Dropdownlist in Gender column at run time, Its getting Disappear. The value in Table also getting deleted.
    I will explain Clearly.for example, I am selecting "male" from gender column at run time. When i clicked update . It will be gone. Y?
    Thanks in advance.

  • @AbumomoS
    @AbumomoS 7 років тому

    wow ty nice vid

  • @waynesmith4336
    @waynesmith4336 10 років тому

    what a man move fast, me rahtid!

  • @stutitehri993
    @stutitehri993 10 років тому

    good tutorial

  • @stephanieezat-panah7750
    @stephanieezat-panah7750 6 років тому

    I always enjoy your videos, Professor, but not for anything could I get this to work. After many internet searches, the following did work; setting the properties AppendDataBoundItems="true" and AutoPostBack="True" in the DDL. thoughts?

  • @lizravenwood5317
    @lizravenwood5317 8 років тому

    I love your teaching, but unfortunately my employee has not given me access to an SQL server to develop. Can you show how to do this using Access database table back end?

  • @DarkCebolix
    @DarkCebolix 10 років тому

    Great video! tranks:)

  • @007iguan
    @007iguan 11 років тому

    For those who had problems with the SelectedValue.. I fixed it by changing the value on my DB For example in my table "Empleados" the first record name is "Peter" but in the Dropdown list doesnt exist the name "Peter". In the dropdownlist there is "Jonh", "Marck",etc but not "Peter". You can fix it backwards, changing the name on the Dropdownlist not in the DB for matching the values. The important thing is that values must match.

  • @kremius12
    @kremius12 9 років тому

    kudvenkat
    Is is possible to dinamically disable updating some columns? For example I want to disable to update some columns for specified user. Can I do that ?

  • @sandeepkumarneelam9920
    @sandeepkumarneelam9920 10 років тому

    Hai Venkat Sir. First i would like to say Thanks for your video Tutorials.
    Sir i have a Problem. (DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value)
    please help me out..

    • @csworld10
      @csworld10 9 років тому

      Sandeep Kumar Neelam hi.
      did u get help for ur query? if yes please help me too

    • @sandeepkumarneelam9920
      @sandeepkumarneelam9920 9 років тому

      Rizwana Abbasi No Buddy

    • @1gouravgg
      @1gouravgg 9 років тому

      Sandeep Kumar Neelam refer here stackoverflow.com/questions/31919133/dropdownlist1-has-a-selectedvalue-which-is-invalid-because-it-does-not-exist-i

  • @MrSuryasj
    @MrSuryasj 11 років тому

    good one thanks

  • @commsoft2923
    @commsoft2923 10 років тому +1

    I would like to use a second sqlconnection with datavalues to be used in the drop downlist
    How can i do that?
    btw. thanks for great videos!

  • @priitroosipuu5177
    @priitroosipuu5177 10 років тому

    Thank you!!!