Link for csharp, asp.net, ado.net, dotnet basics and sql server video tutorial playlists
/ kudvenkat
Link for text version of this video
http://csharp-video-tutorials.blogspo...
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.
/ @aarvikitchen5572
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.
http://csharp-video-tutorials.blogspo...
Step 1: Drag and drop a gridview control, a detailsview control and 2 objectdatasource controls on webform1.aspx.
Step 2: Add a class file, with name = EmployeeDataAccessLayer.cs to your project.
Step 3: Build your solution, so that the employee data access layer class is compiled.
Step 4: Configure ObjectDataSource1 control to retrieve data from EmployeeDataAccessLayer. Use GetAllEmployeesBasicDetails() as the SELECT method.
Step 5: Asscociate ObjectDataSource1 control with Gridview1 control, and make sure "Enable Selection" checkbox is checked.
Step 6: Configure ObjectDataSource2 control to retrieve data from EmployeeDataAccessLayer. Use GetEmployeesFullDetailsById(int Id) as the SELECT method. The value for the parameter - Id should come fromt the selected row in GridView1 control. Also, select INSERT, UPDATE and DELETE methods.
INSERT Method - InsertEmployee()
UPDATE Method - UpdateEmployee()
DELETE Method - DeleteEmployee()
Step 7: Associate ObjectDataSource2 with DetailsView1 control and make sure the following checkboxes are selected.
Enable Inserting
Enable Editing
Enable Deleting
Step 8: Generate ItemInserted, ItemUpdated and ItemDeleted event handler methods for DetailsView1 control.
Step 9: Copy and paste the following code in webform1.aspx.cs
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);
}
Step 10: Set GridView1, DataKeyNames to "Id"
DataKeyNames="Id"
Step 11: Run the application. Select a row in gridview, and click "Edit". Notice that Id is also editable. To make it non editable, set ReadOnly attribute to true.
Step 12: Click on "New" link button in detailsview to insert a new row. Notice that, the interface shows a textbox for Id column. This column in the database is identity column, and we don't have to supply a value for it. To make it invisible, set InsertVisible attribute to false.
Setp 13: Click on Edit, change a few values, and click "Update". Notice that none of the rows are updated. To solve this issue, set DataKeyNames="Id" on DetailsView1 control.
На этой странице сайта вы можете посмотреть видео онлайн asp.net detailsview insert update delete using objectdatasource control - Part 41 длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь kudvenkat 31 Март 2013, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 22,510 раз и оно понравилось 55 зрителям. Приятного просмотра!