Tuesday, 29 December 2015
Sunday, 27 December 2015
Easiest way to bind the data to Dropdownlist in ASP.NET MVC
- For binding the data from database one now do not have to write sql query neither have to go for writing extra code in Model. It is much simple just you need to know the LINQ... that's it.
- We'll see it step by step.
- First we'll create a form and add dropdownlist to it as shown below.
- For binding the data no stuff should be written in Model Class file.... .
- Simply goto controller -> action method and write code.
- In my case I want to bind the Server IPAddress to DropDownList and below is the code.
Sunday, 29 November 2015
Creating and consuming web service in ASP.NET MVC
- First of all we'll create a Web Service and then we'll consume the web service using ASP.NET MVC application.
- This project is created on Visual Studio 2013.
- Open a VS and select ASP.NET Empty web application as shown.
- Then add new item and select Web Service (.asmx) extension would be there, rename if you want. Finally it would be some thing like this.
- Above you can see a [web method] , actually this allows a methods to call remotely and access the data.
- When you'll run the program you'll see HelloWorld method which is created by default. Now there after you'll invoke the HelloWorld which will return output as "Hello World".
- In a same way we'll create a Simple Web Method for addition of two numbers named Calc which will return a string. One can go through below code , we've created new method Calc which takes 3 inputs:
- query: For Add, Multiply, etc
- num1: number
- num2: number
- Here it's only shown for Addition you can do as you want.
- Now after creating the web method you'll see Calc method would be created. For testing your created service you can go to Calc and click.
- After click input Add and two numbers as shown and click on invoke. Be sure it should show result as in XML format and addition of two numbers.
- Now we'll consume a Web Service using ASP.NET MVC application. So create an Empty ASP.NET MVC Application as shown below.
- Before consuming Web Service above created project should be running or hosted on IIS to access.
- Then add that url in this Address and Press Go. Your hosted or running Web Service would be seen in Service Panel as shown.
- For accessing the method give a reference of Web Service in namespace as shown.
- Thereafter create an object as shown by SoapClient and then give input to Web Method by calling the service and you'll get the output.
- And that's it Over. You'll get your data in result and can use in View of MVC application.
Wednesday, 18 November 2015
Bubble Sorting Algorithm in C#
- This article will teach you how use the bubble sort algorithm in c#.
- Yes, this may sometimes be asked in interview also.
- First of all we'll see what is bubble sort algorithm.
Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller elements "bubble" to the top of the list. Although the algorithm is simple, it is too slow and impractical for most problems even when compared to insertion sort.[1] It can be practical if the input is usually in sort order but may occasionally have some out-of-order elements nearly in position.
Class | Sorting algorithm |
---|---|
Data structure | Array |
Worst case performance | ![]() |
Best case performance | ![]() |
Average case performance | ![]() |
Worst case space complexity | ![]() |
Let us take the array of numbers "5 1 4 2 8", and sort the array from lowest number to greatest number using bubble sort. In each step, elements written in bold are being compared. Three passes will be required.
- First Pass
( 5 1 4 2 8 )
( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1.
( 1 5 4 2 8 )
( 1 4 5 2 8 ), Swap since 5 > 4
( 1 4 5 2 8 )
( 1 4 2 5 8 ), Swap since 5 > 2
( 1 4 2 5 8 )
( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5), algorithm does not swap them.

( 1 5 4 2 8 )

( 1 4 5 2 8 )

( 1 4 2 5 8 )

- Second Pass
( 1 4 2 5 8 )
( 1 4 2 5 8 )
( 1 4 2 5 8 )
( 1 2 4 5 8 ), Swap since 4 > 2
( 1 2 4 5 8 )
( 1 2 4 5 8 )
( 1 2 4 5 8 )
( 1 2 4 5 8 )
Now, the array is already sorted, but the algorithm does not know if it is completed. The algorithm needs one whole pass without any swap to know it is sorted.

( 1 4 2 5 8 )

( 1 2 4 5 8 )

( 1 2 4 5 8 )

Now, the array is already sorted, but the algorithm does not know if it is completed. The algorithm needs one whole pass without any swap to know it is sorted.
- Third Pass
( 1 2 4 5 8 )
( 1 2 4 5 8 )
( 1 2 4 5 8 )
( 1 2 4 5 8 )
( 1 2 4 5 8 )
( 1 2 4 5 8 )
( 1 2 4 5 8 )
( 1 2 4 5 8 )

( 1 2 4 5 8 )

( 1 2 4 5 8 )

( 1 2 4 5 8 )

Now we'll try this kind of example in C#. For implementing in bubble sort in C# here is the code:
Sunday, 15 November 2015
Create your own extension in Google Chrome Browser
- Hi all, this article will teach you how to create an extension in Chrome browser. It's very easy you just have to do is follow my steps.
- Now since Google Chrome works with JSON we'll create a .json extension file in one of the folder as shown.
- Now in that file enter following code and save it.
{
"manifest_version": 2,
"name": "Youtube Watcher",
"description": "Watch Videos of youtube",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
}
}
- Now create one html file named popup.html in same folder in which we'll enter following code:
<iframe width="560" height="315" src="https://www.youtube.com/watch?v=UcBn995_tZo" frameborder="0" allowfullscreen></iframe>
- Thereafter we'll create one icon for youtube extension named icon.png where you can save the youtube icon in this image file.
Note : All three files should be in Same folder as shown.
- Now open your Chrome browser and goto->More Tools->Extensions->Check the Developer Mode.
- Now click Load unpacked extensions and select the folder where you have kept all this 3 files.
- It will automatically load your youtube extension.
- You can change anything you want if you are a json expert.
- Thanks, I'll like share you this kind of stuff again.
Saturday, 14 November 2015
CRUD operations in ASP.NET MVC 5 using C#
- This article is for beginners and it's for performing the CRUD operation in ASP.NET MVC 5 using C#. And in next article we'll see Searching, Paging and Sorting a table.
- Note :Download the Visual Studio 2013 or higher so you can grab all the latest features.
- First create a new project in Visual Studio( * in this article 2013 is used) and give appropriate name to it.
- Now after clicking OK one new window will prompt, where it will ask to choose the template. Simply select the empty template and check the MVC as shown in below picture.
- Now after clicking OK, blank ASP.NET MVC solution will be created.
- Before moving forward you need to create a database in Sql Server. I've created a database named TestDB and a table EmpDetails that contains EmpId, EmpName, EmpAdd, EmpNumber field.
- Now for connection of MVC to database we'll use Entity Framework . So we'll goto Tools-> Nuget Packet manager and install the Entity Framework package in our solution. After installation you will see this kind of view.
- Now we'll add the Model(i.e. Class.cs) in Model Folder. Let us name it as EmpDetails.cs. And add namespace :
- using System.Data.Entity;
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- Now add a connection string to the web.config file as shown and make sure that the connection string name is same as of DBContext Entity.... here in my program it is EmpDBContext.
- Now model has been created and we'll create a controller for action.But before creating the controller you've build your application once to effect the changes. So, here's a MVC 5 scaffholding part where you didn't have to do any code scaffholding will do by itself. You just have to do is select the controller by going to Controller Folder-> Add -> Controller-> Select MVC 5 Controller with views, using EntityFramework.
- After selecting , window would be prompted which would ask for Model Class select your Model Class, then select the data context. And controller name would be taken automatically. Click Add. The scaffholding process would be going on which will create one controller named EmpDetailsController.cs in Controller Folder and simultaneously it will also create a View for EmpDetails controller where you would see the Create, Delete, Details, Edit and Index.cshtml files in Views-> EmpDetails folder as shown
- Now just goto->AppStart->RouteConfig.cs and change the controller from Home to EmpDetails and run the applications.
- You will get the output where there would be one table and you can Create , view delete the data of the table.
This is how an easy to develop Application in MVC 5 is done and is quite simpler. For understanding the details code you can go through class file generated in Controller. In next article we're going through that. Have a nice development.
Tuesday, 3 November 2015
Generate random numbers from List in c# using Linq
- This article is to demonstrate how to generate the random number from the generic List<T> using Linq.
- First of all we'll create the list of results which is in ascending order.
- Then we'll select each record from the results, ordered by Guid each time.This gives randomness.
- Thereafter we'll return the list.
- Finally access the list however you want.
Sunday, 18 October 2015
Uploading files larger than 5 mb in ASP.NET
- One of the small stuff that some of the freshers are messing with is uploading the file of size larger than 5 MB or more.
- It is really so easy to resolve, the thing you need to do is just add a <httpruntime/> tag to your web config file under <system.web> as shown and that's it done.
- You may change the size 16384 (16 MB) to what ever you want e.g 4096, 8192 or 65536 (64 MB).
- Enjoy the coding.
Friday, 2 October 2015
Access the .NET Server Controls using javascript easily
- There are many developers that are depend on intellisense provided by Microsoft Visual Studio.
- But some times it may not work for scripting, though in VS 2012 and higher version it quite run much good.
- So here are some of the JS code that I would like to share with developers for accessing the .NET controls and how to retrieve and set value to controls.
- Get Label Value:
- $('#<%=Label.ClientID%>').text();
- $('#<%=Label.ClientID%>').text("New Value");
- Get Textbox value:
- $('#<%=TextBox.ClientID%>').val();
- $('#<%=TextBox.ClientID%>').val("New Value");
- $('#<%=DropDownList.ClientID%>').val();
- $('#<%=DropDownList.ClientID%>').val("New Value");
- $('#<%=DropDownList.ClientID%> option:selected').text();
- $('#<%=CheckBox.ClientID%>').attr('checked');
- $('#<%=CheckBox.ClientID%>').attr('checked',true);
- $('#<%=CheckBox.ClientID%>').attr('checked',false);
- Get Radiobutton Status:
- $('#<%=RadioButton.ClientID%>').attr('checked');
- $('#<%=RadioButton.ClientID%>').attr('checked',true);
- $('#<%=RadioButton.ClientID%>').attr('checked',false);
- $('#<%=TextBox.ClientID%>').attr('disabled', true);
- $('#<%=TextBox.ClientID%>').attr('disabled', false);
- $('#<%=TextBox.ClientID%>').attr('readonly', 'readonly');
- For getting the data you may also use as what I have said in previous blog, that is simpler
Tuesday, 22 September 2015
ORA:06413 Connection not Open
- This blog is for those who want to connect Visual Studio with Oracle Database 10g or lower upto 9i.
- I seen there are lots of problem while connecting the Visual Studio with the Oracle 10g and 9i.
- I would like to share that Oracle has already left the support for the same & so as the patch for connection.
- Then instead of using Oracle 10g or 9i client for connection with Oracle Server use the client for which Oracle Corporation use to give support.
- I had the same problem , all code and path variable were checked and were perfect. But then also Client was not connecting to oracle 10g Server.
- Even though from SQL PLUS it was connected.
- Thereafter I just uninstalled Oracle 10g client and installed Oracle 11g R2 32-bit and placed tns file in ADMIN folder of OracleHome.
- I checked once again from VS 2010 and VS 2012 and executed code. The server was connected.
For any query you may comment . Yours comments would be appreciated.
Thursday, 10 September 2015
Get the data from server controls using javascript in asp.net
- Today I'll show you how to retrieve the server controls data easily using Javascript in ASP.NET.
- Normally people I have seen use to retrieve the data from controls is using something like this:
function validate()
{
var text=document.getElementById('<%=TextBox1.ClientId%>').value;
// do stuffs
}
- And then more code for if you want dropdownlist data and some other controls.
- Instead simply one can use String function as (e.g. for DropDownList):
function validate()
{
var text=String('<%=DropDownList1.SelectedItem.Text%>');
var value=String('<%=DropDownList1.SelectedItem.Value%>');
// do stuffs
}
- That was for this blog have a great day. And yes any one having difficulty can comment anytime.
Wednesday, 26 August 2015
Insert the data/password by using Cryptography (Encryption/Decryption)
- Always store password using reversible encryption so as the encrypted password can also be decrypted when need to be used.
- But at the same time it is also important to use the strong encryption algorithm.
- Here I'll demonstrate you one of the method for encrypting the data and storing them into database. And Vice-versa.
- Two Class file one is DBAccess where all database stuffs are done and another EncDecClass file for encrypting and decrypting the data.
- This code shows the button click event for storing the encrypted password into database. It calls "Encrypt" method of Class file for encrypting the password.
- Now let us see how Encrypt method works:
- And yes this is it. Here your password get decrypted.
- For more information leave comments please.
- And let me know the difficulties you are facing I'll definitely try to sort it out if I had gone through it.
- Good Luck!
Subscribe to:
Posts (Atom)
How To Pass An Array As A Parameter While Calling an ASP.NET Web API C#
Please visit my C# Corner Blog for this, where I have provided better efforts to make this concept more understandable - www.c-sharpcorner....
-
This article will teach you how use the bubble sort algorithm in c#. Yes, this may sometimes be asked in interview also. First of all ...
-
This post will show you detailed information about how to host your webpage on google drive. It's really very simple job to host a w...
-
This blog is for those who want to connect Visual Studio with Oracle Database 10g or lower upto 9i. I seen there are lots of problem whi...