Posts

Showing posts with the label FormView

Donate

ASP.NET FormView CRUD With Entity Framework (VB.NET)

Image
The VB.NET version of this post ASP.NET FormView CRUD with Entity Framework is provided in the ASP.NET Codebank section of VBForums ASP.NET FormView CRUD (Create, Update, Delete) with Entity Framework . Screenshots

ASP.NET FormView CRUD With Entity Framework

Image
Most of the examples on FormView Web Server control use DataSource wizard controls such as SqlDatasource or ObjectDataSource when assigning value to the FormView's DataSource property. However, using those controls have drawbacks such as maintainability. I also found samples out there using ADO.NET. Enough with the chit-chat and let's proceed with coding. I'll post the create table statement, code behind and the aspx markup. SQL Code: USE [Books] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[BookDetails]( [BookSerialNo] [int] IDENTITY (1,1) NOT NULL , [BookISBN] [ nchar ](15) NULL , [BookTitle] [varchar](120) NULL , [BookAuthor] [varchar](60) NULL , [BookPublisher] [varchar](50) NULL , [BookCategory] [varchar](20) NULL , PRIMARY KEY CLUSTERED ( [BookSerialNo] ASC ) WITH (PAD_INDEX = OFF , STATISTICS_NORECOMPUTE = OFF , IGNORE_DUP_KEY = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_...

DataKey Value Is Null In ItemDeleting Event Of ASP.NET Web Forms FormView Control

Image
Hello, Normally, you can access the DataKey object value of a FormView control to it's wired events. Since I'm using Entity Framework as Datasource of a FormView control instead of DataSource control wizards, the DataKey object value of the FormView control returns null instead of an ID in the ItemDeleting event of that object. After putting several breakpoints to it's events, I came up with a fix that is to query the DB again and then bind it's result to the DataSource property of the FormView Control. That is call BindFormView() method when CommandName is equal to "Delete" in the ItemCommand event of the control. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 protected void FormViewBookDetails_ItemCommand( object sender, FormViewCommandEventArgs e) { if (e.CommandName == "Cancel" ) { FormViewBookDetails.ChangeMode(FormViewMode.ReadOnly); } else if (e.CommandName == "Edi...

Donate