asp.net detailsview insert update delete using sqldatasource control - Part 40

preview_player
Показать описание

Link for text version of this video

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 YouTube channel. Hope you can help.

In this video we will discuss about inserting, updating and deleting data using detailsview and sqldatasource control.

When the webform is loaded, the gridview control, should retrieve and display all the rows from tblEmployee table. As soon as I select a row, in the gridview control, then all the columns of the selected row, should be displayed in details view control. Then, we should be able to edit, delete and add a new employee using the DetailsView control.

We will be using tblEmployee table for this demo. If you need sql script to create this table, please refer to Part 37 using the link below.

Step 2: Configure SqlDataSource1 to retrieve [Id], [FirstName], [City] columns from tblEmployee table

Step 3: Associate SqlDataSource1 with GridView1 control

Step 4: Configure SqlDataSource2 to retrieve all columns from tblEmployee table. Add a WHERE clause to filter the rows based on the selected row in GridView1 control.

Step 5: While configuring SqlDataSource2 control, click on "Advanced" button, and make sure "Generate INSERT, UPDATE and DELETE statements" checkbox is selected.

Step 6: Associate SqlDataSource2 with DetailsView1 control and make sure the following checkboxes are selected.
Enable Inserting
Enable Editing
Enable Deleting

Step 7: Generate ItemInserted, ItemUpdated and ItemDeleted event handler methods for DetailsView1 control.

protected void Page_Load(object sender, EventArgs e)
{
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (GridView1.SelectedRow == null)
{
DetailsView1.Visible = false;
}
else
{
DetailsView1.Visible = true;
}
}
protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
GridView1.DataBind();
GridView1.SelectRow(-1);
}
protected void DetailsView1_ItemDeleted(object sender, DetailsViewDeletedEventArgs e)
{
GridView1.DataBind();
GridView1.SelectRow(-1);
}
protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
{
GridView1.DataBind();
GridView1.SelectRow(-1);
}
Рекомендации по теме
Комментарии
Автор

15/10 You teach much better than any instructor I have ever had in regards to programming. 

TheDream
Автор

Mr.Venkat,
      I am very thankful to you for the video.

nargeez
Автор

Thank you for your videos Venkat, You are helping us alot

robertosterberg
Автор

Thanks man, i've looked for an update command after refreshing. Very helpful ) Subscribed.

Therapyxx
Автор

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.

Csharp-video-tutorialsBlogspot
Автор

Thank you
Venkat
your video more use full for me
thanks

rajputkamlesh
Автор

Hi, you can use time control, to postback every 5 or 10 seconds and then you can load a different image on the postback. You can use ajax update panel, if you want the photo transition to be smooth without a full page refresh. If this is confusing I will record and upload a video as soon as I can. Good Luck.

Csharp-video-tutorialsBlogspot
Автор

The only thing missing is if you have no records and wish to add a new one. Best to leave the detailsView visible. (though, I don't see a blank box when I reproduce your example, but, instead, see a detailsView with all the fields shown with empty values).
Another note is that when inserting a new record, a textbox is shown for the ID field even though it is readonly (maybe it should be templated as well).

docdaven
Автор

Appreciate all your efforts K, but wish you'd show us the source of the ASPX page. My update statement just not working. Looks like VS is overwriting parameter variables

Russellyeman
Автор

i would like to buy all your videos, nice explanations but there's no header detail example?

rickytik-devops
Автор

Is there any way to change the textbox size after you hit edit on a record? I have some fields which contain paragraphs.

PrelaE
Автор

my advance options (EDIT, DELETE & INSERT) are not enabled for GridView and DetailView control. I can't select check box. Do know why?

cpachch
Автор

Hi
I have followed your videos, and have a problem now. I get an error: Non-invocable member can not be overused like a method.
What have I done wrong. Hope you will help me. Thanks in advance.

jeanetteseifert
Автор

Sir can you suggest me that how to insert image path with string value using fileupload control in detailview. i am trying to much but failed every time. please help me

AeSIShailendra
Автор

mr kudvenkat....well done, i have to ask you bro. how can i add slideshow to photo galery ..can u help me out?

a.ksomal
Автор

hi . Are you fine ?? Kudvent!Kat Your videos is very large and usable thank you for all Please can give me a link to your video that you put it in youtube who you are explain All properties of the Listviews .Or you explain the all methode to the listview in asp.net c# and in ado.net c# .Please it's urgent .Thank you so much have a good day.

fadouajaouhar
Автор

All Works for me up until using the WHERE clause. When running without debugging after that, the Details view does not show and when clicking Select on Gridview, Error is generated :
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request.

....maybe I missed a step?

vibewireless
Автор

nice video :)
i have a problem, update works but delete and new don't.
when i click delete the sugar layout appears, and the grid stil stays the same, and when i click new i get an error page, i don't have the insert event on my Visual studio express 2010, i have RowEditing...can you help me out :D
i need to do a DropBox application of my own for a seminar :) 
Tnx

kostapopovic
Автор

Is this also possible with ObjectDataSources? :o

Barrosy
visit shbcf.ru