Posts

Asp.Net MVC: With Product example 1

Web.config  - Add the connection string <connectionStrings>     <add name="ProductDBConnectionString" connectionString="Data Source=LK-PRK\SQL2012DEV;Initial Catalog=ProductDB;Integrated Security=True"         providerName="System.Data.SqlClient" />   </connectionStrings> Connections.cs - in Model section using System.Configuration; using System.Data.SqlClient; namespace TestStock.Models {     public class Connection     {         public static SqlConnection GetConnection()         {             var conn = ConfigurationManager.ConnectionStrings["ProductDBConnectionString"].ConnectionString;             return new SqlConnection(conn);         }     } } Products.cs  - in Models section namespace TestStock.Models {     public class Product ...

.Net Better structure : With Product sample - Insert Data from JavaScript (3)

In this post we are going to call C# function using jQuery Ajax. jQuery Ajax help to send client side request without doing a post back. This allow to trigger an asynchronous (you can do synchronous as well, but what is the point ?) Add the jQuery libry to your page header. Find this from Google or Microsoft CDN. I'll take from Google CDN. https://developers.google.com/speed/libraries/#jquery Create a JavaScript file under folder called Scripts and name that file as Script.js. Add the following script to that file. Using this script file we are going to call a server side method which is written in C#. Script.js function AddProduct() {     var name = document.getElementById('txtProductName').value;     var price = document.getElementById('txtProductPrice').value;     if (name == "") {         alert("Enter product name !");     }else if (price == "") {         alert("Enter product price ...

.Net Better structure : With Product sample - Insert Data from C# (2)

Hi all, this is the 2nd post of this series. In this post I'll try to explain how to insert data to a database while keeping a better structure in your Visual Studio ASP.Net application. First lets create this (or similar to this) Stored Procedure in your database to add products. AddProducts Stored Procedure SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE AddProducts @name varchar(50), @price decimal(8,2) AS BEGIN SET NOCOUNT ON; INSERT INTO Products VALUES (@name, @price); END GO Inside the Domain folder of your project, create the following class. Product.cs namespace TestWeb.Domains {     public class Product     {         public int Id { get; set; }         public string Name { get; set; }         public double Price { get; set; }     } } Under the DomainHelpers folder, inside ProductHelper class add this code. ProductHelper.cs publi...

.Net Better structure : With Product sample - Get Data (1)

Hi all, in this series of blog posts I'll explain how to create ASP.Net web applications using a better structure. This is the part 1 of this blog series, so in this post I'll try to explain how to retrieve data from database. First go tot the Visual Studio and create a ASP.Net Empty Web Application project. Give a suitable name (I'll be using TestWeb). Create database and tables with some sample data. Now lets connect to that database using a connection string. Web.config <?xml version="1.0"?> <!--   For more information on how to configure your ASP.NET application, please visit   http://go.microsoft.com/fwlink/?LinkId=169433   --> <configuration>     <connectionStrings>         <add name="ProductDBConnectionString" connectionString="Data Source=LK-PRK\SQL2012DEV;Initial Catalog=ProductDB;Integrated Security=True"             providerName="System.Data.SqlClient" /...

Working with ASP.Net controls to Insert, Update and Delete with SQL Server Database - No Coding

Image
Working with ASP.Net controls to Insert, Update and Delete with SQL Server Database - No Coding This blog will teach you how to create a simple application using ASP.Net controls and MS SQL database. We are going to do this without any back end C# codeings. :) Following shows the page that we are going to create. It has function to: 1. Show some data (I use Employee data) 2. Manage those data (Insert, Update, Delete) Step 1 Go to Visual Studio. Create a "ASP.NET Empty Web Application". Step 2 Create a new aspx page. I'll create a page called home.aspx. Step 3 To show, update and delete data we will use - ASP GridView To insert new data we use - ASP DetailsView To bind the data to these controls we use - SqlDataSource Drag and drop following ASP controls from the Visual Studio toolbox to the home.aspx. Switch to the design mode and drag and drop those controllers as you want. On the GridView and the DetailsView, set the SqlDataSource...

ASP.Net MVC Tute 4 - Create a List from IList

Image
ASP.Net MVC Tute 4 - Create a List from IList In this post I'll explain how to show data in a list. I have define this inside the Controller's Item ActionResult. You can arrange these in proper locations. 1. Create IList using a Model.         private static IList<Item> items = new List<Item>()         {             new Item()             {                 Id = 1,                 ItemName = "iPhone",                 Price = 99000             },             new Item()             {                 Id = 2,                 ItemName = "Lumia 520",         ...

ASP.Net MVC Tute 3 - Data Passing and Navigation

Image
ASP.Net MVC Tute 3 (Starter) - Data Passing and Navigation Let's see what are the other methods that provided to pass data to Views and Navigate using links. View Data and View Bag ViewData is a dictionary like data type. Inside controller: ViewData["ItemData"] = "Item data"; Inside View: View Data: @ViewData["ItemData"] ViewBag is dynamic data type Inside controller: ViewBag.ItemBag = "Item data in a bag"; Inside View: View Bag: @ViewBag.ItemBag TempData is use to store data that is survive for redirect. Inside controller: TempData["Survive"] = "Item data survived"; Inside View: Temp Data: @TempData["Survive"] URL Navigation 1. Lets create another ActionResult in ItemsController.         public ActionResult Item()         {             return View();         } 2. Create a view called Item by right click on the View and Add View. <!DOCTYPE html> ...