Posts

Showing posts from March, 2016

Donate

VBForums CodeBank Entries

ASP.NET/ASP.NET MVC Using Bootstrap Typeahead.js Plugin in an ASP.NET MVC Project Using AJAX Control Toolkit AutoCompleteExtender in ASP.NET 4.5 ASP.NET MVC ListBoxFor() with optgroup Tag support ASP.NET FormView CRUD (Create, Update, Delete) with EF Using jqGrid with ASP.NET MVC 5 Visual Basic.NET ASP.NET MVC 5 Form Validation using jQuery and Bootstrap w/o Model Alphabetical Paging in ASP.NET MVC Bootstrap Modal Dialog in ASP.NET 4.5 ASP.NET GridView CRUD with Bootstrap (VB.NET) ASP.NET MVC TextBox Helper Watermark Databinding ASP.NET GridView with jQuery Read-only column on GridView Row Editing Change GridView SortLink Color in ASP.NET 4.0 Change ASP.NET Label control value using continuous mouse down click C#.NET

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

DataGridview Check For Duplicate Values And Group Code In Separate Column

Image
Hi, I've always been a desktop developer ever since Visual Basic 6.0 came into existence. While I'm busy doing projects for the web platform, I always go back to my roots of solving desktop issues in .NET. :-D Well, going back to the issue, a certain member in Visual Basic forums posted an issue on how to check duplicate values in a particular datagridview column with DateTime as type. Once a duplicate value has been detected, the code number will be grouped in another datagridview column with label total. See sample screenshot for the desired output: After creating the logic, I proceed to converting it to code. 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 private void SpotDuplicates() { int i = 0; int j = 0; for (i = 0; i <= dgvDates.RowCount - 1; i++) { for (j = 0; j <= dgvDates.RowCount - 1; j++) { if (i > j) { if (Convert.ToDateTime(dgvDates[0

Migrate SQL Server Compact Database SDF to SQL Server MDF File

Image
As I was migrating an old project from a client to a new platform, his database was a SQL Server Compact 4.0. Lol, I haven't used this type of database in my entire career. :-D His objective was to migrate the schema and it's data to SQL Server 2012. Given the task, I made some research and came up with a tool created by ErikEJ on Scripting API samples. That is integrate some assemblies to the project and create some functions to write the schema and it's data to an external file. Here's an example on how to use the tool. 1. First, make sure that the database file's Read-Only property is unchecked. 2. Create a C# console project then add the following assemblies ISqlCeScripting.dll, SqlCeScripting.dll and SqlCeScripting40.dll 3. Reference ErikEJ namespace in your project. 1 using ErikEJ.SqlCeScripting; 4. Function to generate table scripts including their constraints. 1 2 3 4 5 6 7 8 9 10 11 12 13 private static void GenerateCreateTable

Enable ASP.NET Control After Validation Of Prior Control Succeeded Using JavaScript In ASP.NET

Given you have a simple form below with two TextBox controls. The second TextBox is disabled during pageload. Ifyou want to enable the second TextBox control if the validation of the first/prior control succeeded, the solution for this is using client side approach which is to check the visibility property through JavaScript/jQuery. HTML Code 1 2 3 4 5 6 7 8 9 10 11 <div id= "ContactForm" > <asp:Label id= "lblEmail" Text= "Email Address:" AssociatedControlID= "txtEmail" Runat= "server" /> <asp:TextBox id= "txtEmail" Runat= "server" /> <asp:RegularExpressionValidator id= "regEmail" ControlToValidate= "txtEmail" Text= "(Invalid email)" ValidationExpression= "\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Runat= "server" /> <asp:Label id= &qu

An error occurred creating the configuration section handler for spring/context: Could not load file or assembly 'Spring.Web' or one of its dependencies.

As I was integrating Spring.NET via NuGet, I had difficulties in referencing the assemblies to work with an ASP.NET MVC application. Such that I encountered the error specifically in web.config namespace Spring.Context.Support.WebContextHandler . The workaround for this issue is to uninstall the Spring.NET which I installed earlier through NuGet and instead download Spring.NET1.3.1 from Spring Framework website and reference the assemblies below to my project. List of assemblies: Spring.Core.dll Spring.Data.dll Spring.Web.dll Spring.Web.Mvc.dll Common.Logging.dll

An object with the same key already exists in the ObjectStateManager. (Entity Framework 6.0)

The code below for updating of objects worked with Entity Framework 5 and below. But using this with Entity Framework 6.0 and Castle Windsor as IOC Container, I get an error message with is the title of this post. 1 2 3 4 5 6 7 8 public void Update(BookDetail item) { if (item!= null ) { _context.Entry(item).State = System.Data.Entity.Entitystate.Modified; _context.SaveChanges(); } } So to fix this, replace the code above with DBContext.Entry(T Entity).CurrentValues.SetValues(T Entity). 1 2 3 4 5 6 7 8 9 10 11 12 public void Update(BookDetail item) { if (item != null ) { var result = _context.BookDetails.Find(item.BookSerialNo); if (result != null ) { _context.Entry(result).CurrentValues.SetValues(item); _context.SaveChanges(); } } }

How To Wrap Text Inside A JqGrid Cell

Image
When showing records from a datasource, you may wonder why a certain JqGrid cell does not wrap the entire text into it's cell. An example would be a lengthy description, notes or remarks, and address. After doing some research, the fix is to add a cellattr to the grid's cell and set it's white space property to normal. JqGrid Address Cell without cellattr property 1 { name: 'Address' , index: 'Address' , width: 200, align: 'left' } JqGrid Address Cell with cellattr property 1 2 3 { name: 'Address' , index: 'Address' , width: 200, align: 'left' , cellattr: function (rowId, tv, rawObject, cm, rdata) { return 'style="white-space: normal;"' }},

How To Integrate JqGrid In ASP.NET MVC 5

Image
Hi, Here's a simple demo using jqGrid in ASP.NET MVC 5 Visual Basic.NET. The detailed instructions are elaborated in VBForums ASP.NET Codebank. The NuGet packages needed are: 1. Dynamic LINQ Library 2. jqGrid 4.6.0 Sample Screenshot: Setup and Source Code: Using jqGrid with ASP NET-MVC 5 Visual Basic.NET

Donate