Posts

Donate

Export ASP.NET GridView To Excel And Preserve Leading Zeros

Image
Hi, There was a question raised on how to export data from ASP.NET Gridview to Microsoft Excel and preserve leading zeros of numeric values. A workaround that we have is to insert an   character before the cell value if that value starts with zero (0). So if the value starts with zero such as 0001, the result would be " 0001". Thus when exported to Excel, the leading zero is kept. cell.Text = string .Format( " {0}" , cell.Text); A suggested solution is to insert a Tab character ( ) but this fails on some occasions. After doing some research, replacing the tab character with   or   would also fix the issue. cell.Text = string .Format( " {0}" , cell.Text); //or cell.Text = string .Format( " {0}" , cell.Text); ASP.NET GridView Export Excel Report Cheers!

WPF DataGrid Data Binding Using MVVM Pattern

Image
Hello, I've been developing WPF applications before but not having applied the MVVM design pattern and have been wanting to create a simple program that loads data into the DataGrid control. As a result of free time, here's a simple demonstration on using MVVM Pattern for Data Binding a WPF DataGrid control. According to Wikipedia, the components of an MVVM pattern are: Model Model refers either to a domain model, which represents real state content (an object-oriented approach), or to the data access layer, which represents content (a data-centric approach). View As in the MVC and MVP patterns, the view is the structure, layout, and appearance of what a user sees on the screen. View model The view model is an abstraction of the view exposing public properties and commands. Instead of the controller of the MVC pattern, or the presenter of the MVP pattern, MVVM has a binder. In the view model, the binder mediates communication between the view and the data binder.The view...

Disable Button In AngularJS Using ng-disabled On It's First Page Load In ASP.NET MVC

Hello, One might notice that during page load of an ASP.NET MVC application, the button with ng-disabled attribute and have values such as $invalid or $dirty does not disable the button. Thus, this will enable the user to submit the form with empty values to the controller method. In order to disable the button on page load, add $pristine values in the ng-disabled attribute such as the code below. Original Code <input type= "submit" id= "btnAddEmployee" class = "btn btn-primary" value= "Save" ng-click= "Save()" ng-disabled= "AddEmp.fname.$dirty && AddEmp.fname.$invalid || AddEmp.lname.$dirty && AddEmp.lname.$invalid || AddEmp.salary.$dirty && AddEmp.salary.$invalid" /> Modified code with $pristine <input type= "submit" id= "btnAddEmployee" class = "btn btn-primary" value= "Save" ng-click= "Save()" ng-disabled= ...

$location.path() Method Not Reloading New Data In ASP.NET MVC Web API With AngularJS

Hello, I was trying to integrate AngularJS into a simple ASP.NET MVC Web API application with Save functionality. Basically, when you have finished posting data the next logic will be to redirect the user to the display all page. However, I stumbled into an issue in which the $location service does not reload data. According to the docs,the $location service allows you to change only the URL; it does not allow you to reload the page. So after placing breakpoints in the Api Controller, I noticed that the GetAll() method is called first next is the Save() method. The solution to this dilemma is to transfer the $location.path() method inside the success function so that the Save() method in the Api Controller is executed first. Code With Issue: $location.path() is outside the success function. $scope.Add = function () { $http({ method: "POST" , data: $scope.employee, url: "/api/employees" }) .then( function (response) { $scope.employees = response.data; ...

Adding ASP.NET 5 Templates To VS 2015

Image
Good day! One might notice that the ASP.NET 5 templates are not visible when creating a new Web Application Project in Visual Studio 2015 given that this is a fresh installation of the software. So to add the ASP.NET 5 Templates, download the ASP.NET 5 run-time tools Microsoft ASP.NET and Web Tools 2015 (RC) – Visual Studio 2015 and proceed with the setup. Restart your machine afterwards. That's it.. :-)

This version of Visual Studio requires the April 2014 update to Windows 8.1 (VS 2015)

Hello, Now that I've got the time to install Visual Studio 2015 Enterprise on my laptop with Windows 8.1 Operating System I decided to give it a go. That's when the moment I opened the installer file, an issue pops out of the screen with the description " This version of Visual Studio requires the April 2014 update to Windows 8.1 and Windows Server 2012 R2 known as KB2919355 ". The solution to this issue can easily be found at stackoverflow. But missing the links of the packages needed to resolve the problem. A step by step example is presented below. 1. Download update package 2919442 and install update to your pc. This is the pre-requisite update of package 2919355     x86     x64 2. Download update package 2919355 and install update to your pc.     x86     x64 3. After those updates have been installed, restart the computer for the updates to take effect. Cheers! :-)

How To Post JSON Data With WebRequest In .NET

Hello, There was a question on how to post a JSON data using the WebRequest class on both C# and VB.NET given that using Ajax, the post data would look like this. data : '{ "age": "78", "weight": "51" }' In .NET, you need to store the JSON data into a string object and escape those double quotes before passing it to the WebRequest object. C#.NET string postData = "{ \"age\": \"78\", \"weight\": \"51\" }" ; VB.NET Dim postData As String = "{ ""age"": ""78"", ""weight"": ""51"" }" Cheers! :-)

Sorting Of <li> Elements Using jQuery sort() Method Not Working (Refresh Page Only) In ASP.NET

Given the simple sorting code below which changes the order of <li> elements to ascending order and assuming that the text content of each li elements are numbers. $( function () { $( '#sortList' ).click( function (e) { // Select all the li items var numbersList = $( '#numbersList li' ); numbersList.sort( function (a, b) { return parseInt ($(a).text(), 10 ) > parseInt ($(a).text(), 10 ); }).appendTo(numbersList.parent()); }); }); The code should work only to find out that the page will only refresh after the button click. And then the re-arranging of the elements are discarded. The simple fix to this issue is to add the preventDefault() to prevent the button's default behavior that is to post back. $( function () { $( '#sortList' ).click( function (e) { e.preventDefault(); var numbersList = $( '#numbersList li' ); numbersList.sort( function (a, b) { var temp1 = parseInt($...

$.getJSON() Not Loading JSON File Within Visual Studio Project In ASP.NET Web Forms

Hi, I was trying to load a JSON file located within my Visual Studio project using $.getJSON(), however the code below doesn't work as expected. $.getJSON( '/Assets/misc/employee.json' , function (data) { alert( 'processing!' ); }) .done( function (r) { alert(r.message); }) .fail( function (s) { alert( 'oops the file is missing!' ); }); After investigating for a few hours, I tested the local path of the JSON file such as http://localhost:3766/Assets/misc/employee.json and the result was an exception " HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map. ". I remember the solution in one of my ASP.NET project was to set the MimeMap in the web.config inside the system.webServer element. After setting the MimeMap for json files, I can now load local JSON files using $.getJSON(). <system.web...

Visual Studio Showing Only "Attach" And No Debug Options In ASP.NET Project

Hello, Last night my computer shuts down unexpectedly due to power outage and when I opened an ASP.NET project this morning, it only shows "Attach" in the debug options. Running to different browsers such as Google Chrome, Firefox and Internet Explorer were missing. After a few search, I encountered a solution which is to set again the ASP.NET Project as StartUp Project by right clicking the project and selecting the option Set as StartUp Project . That's it.. :-)

Donate