Tuesday, 1 November 2016

How to use JSON with ajax in ASP.NET?

In this article we learn how to use Ajax with Json in asp.net. It is very easy to call page method using ajax & Json. In this article we will call code behind method using jquery & Ajax. We can pass value or parameter from client end to server side using Json.

click Image to Enlarge it

Tuesday, 19 July 2016

Import Data from Multiple Excelsheets to Multiple table in database in Asp.Net.

In this article I will explain how to Import data from Excel sheet with multiple worksheets to multiple table.

In this article I will Import data from Two worksheets to Two Table in SQL database.

 1.     Create a excel sheet with two worksheets, as given in example.
 2.     Now create two same tables in SQL database.
 3.     Keep in mind, Column name must be same in SQL Table & Excel Sheets.
 4.     Now write given code on button click event to import data from excel sheet to database tables.

Monday, 4 July 2016

Thursday, 9 June 2016

Chart control in C# window application.

Chart: The chart control is used to display your data as a Chart like Pie chart, Line Chart, Point chart, Column, Bar & Area chart. The Chart control visualizes your data. 

In this article, we will learn how to use chart control in window application using c#. We will learn how to bind chart control to database.
In this article I will show data in chart control from database. We can type of chart control in properties of series added. Chart can be of any type: Column. Bar(Stacked Bar), Line, Point, pie chart, Area chart etc.

Follow these steps:

  1.       Add a window form in application.
  2.       Place a chart control on form and Add series to chart control.
Chart control ->Properties-> Series-> Add series (Give name to series)
  3.       Now bind chart control to database using code in code behind.
  4.       Set X-Value member and Y-value member in chart control series.
  5.       Now execute the form.

Create a table in database:

Now place chart control and add series

Now Add Series to Chart Control:

Now Right following code in code behind file on Page Load Event

Add Following Name Spaces:

using System.Data.SqlClient;
using System.Configuration;

Full code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace WindowsFormsApplication1
    public partial class Form3 : Form
        public Form3()

        private void Form3_Load(object sender, EventArgs e)
            DataTable dt = new System.Data.DataTable();
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
            SqlDataAdapter adp = new SqlDataAdapter("Select * from Employee", con);
            chart1.DataSource = dt;
            chart1.Series["Salary"].XValueMember = "Name";
            chart1.Series["Salary"].YValueMembers = "Salary";
            chart1.Titles.Add("Salary chart");


Monday, 16 May 2016

Sorting Gridview Using Jquery Table Sorter plugin.

Sorting is very much needed while working with Gridview. We can sort data using code in code behind file and also using Jquery.

In this article I will use jquery  TableSorter plugin to sort data in gridview. It is very easy to implement.

Create a table:

Click on Image to Enlarge View

Now add a simple webform in your application. Add following jquery CDN and Jquery code to head section of HTML markup.

Friday, 13 May 2016

Show File icons with filename in Asp.Net.

In asp.net we can show file Icons according to file extension. It looks attractive if we show Icons with file name in gridview or othe places. In this article I will explain how to show icon with file name according to its extension.
This concept is based on extension of the file. We will check the extension of the file and show the icon accordingly.

Wednesday, 4 May 2016

Execute or Run JavaScript code from code behind in Asp.Net.

While working in Asp.Net, we need to execute JavaScript code from code behind. In this article I will explain how to execute JavaScript code in Code behind.

Function to Run/ Execute JavaScript code in Code behind in Asp.Net: 

public void RunJavaScriptCode(System.Web.UI.Page page, string strCode)
        string strJavaScriptCode = "<script language=\"javascript\" type=\"text/javascript\">";
        strJavaScriptCode += strCode;
        strJavaScriptCode += "</script>";

        if (!page.ClientScript.IsClientScriptBlockRegistered("alert"))
            ClientScript.RegisterClientScriptBlock(GetType(), "alert", strJavaScriptCode);