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);

Tuesday, 3 May 2016

How to download any type of file from FTP server in ASP.NET (C#)?


We can download all type of file like  CSV, Docx, PNG, JPG, PDF etc from FTP server in asp.net using c#. I have share the code in this article.. We can download any type of file from server using this code. Just change the Extension of the file or mention multiple files extension.

Code to Download All type of Files(CSV, Docx, PNG, JPG, PDF) from FTP Server:

Monday, 2 May 2016

Open or View all type of files (Like Images, Docx, Pdf etc) in ASP.NET(C#)

In this article I will explain How to open or view files in Gridview. While working with Gridview we face a situation where we want to show filename in Gridview  and want to open them on click. Like given in Attached Image.
Open/View Files in Gridview(Click Image to Enlarge view)

Sunday, 1 May 2016

Dynamic control inside Repeater using placeholder in Asp.Net(c#)?

In this article I will explain how to create dynamic control inside repeater using placeholder. Using placeholder we can add dynamic control from code behind like TextBox, RadioButtonList, Checkbox etc (depending upon the condition).
In this Example, I am creating small Question paper with different options to give your answer, Like Textbox to enter your answer, Radio button list to select answer and checkboxlist to select multiple answers.
Click on image to enlarge view

Follow these steps:
      1. Create a simple web form in your application.
      2. Now add a Repeater control to this web form.
      3. Customize repeater control as per your requirement and add a Placeholder control where you want     to insert Input control.
      4. No add ItemDataBound event handler.
      5. Bind Repeater and write code on ItemDataBound event handler to generate Dynamic control.

Create a Table in database:

Design or Html Part of Demo Application:

<asp:Repeater ID="rptPrint" runat="server" OnItemDataBound="rptPrint_ItemDataBound">
  <table style="width: 7.6in">
<td colspan="5" style="width: 7in">
  <asp:Label ID="LblQuestion" Text='<%#Eval("Question")%>'         runat="server"></asp:Label></strong><br />
<asp:HiddenField ID="hfAnswer" Value='<%#Eval("Answer") %>' runat="server" />
<asp:HiddenField ID="hfType" Value='<%#Eval("Type") %>' runat="server" />

<td colspan="4">
<asp:PlaceHolder ID="phRow" runat="server" />
 <br />


Now write the following code in Code behind:

Add Following Namespace:

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

Now Bind Repeater on Page Load and Generate Dynamic control on ItemDataBound:

protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)

private void Fill_Repeater()
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
if (con.State == ConnectionState.Open)

SqlDataAdapter adp = new SqlDataAdapter("Select * from Question", con);
DataTable dt = new DataTable();

if (dt.Rows.Count > 0)
rptPrint.DataSource = dt;

protected void rptPrint_ItemDataBound(object sender, RepeaterItemEventArgs e)
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
string options = ((HiddenField)e.Item.FindControl("hfAnswer")).Value;
string type = ((HiddenField)e.Item.FindControl("hfType")).Value;
Label lblquestion = ((Label)e.Item.FindControl("LblQuestion"));

PlaceHolder phRow = (PlaceHolder)e.Item.FindControl("phRow");

if (type == "Text")
TextBox txtAnswer = new TextBox();

//Check Box Options for Questions

else if (type == "Check")
CheckBoxList chklist = new CheckBoxList();
chklist.RepeatDirection = RepeatDirection.Horizontal;
chklist.Font.Italic = true;

chklist.RepeatColumns = 4;

foreach (string option in options.Split(','))

ListItem items = new ListItem();
items.Text = option;
items.Value = option;

//Radio options for Question

RadioButtonList rdblist = new RadioButtonList();
rdblist.RepeatDirection = RepeatDirection.Horizontal;
rdblist.Font.Italic = true;

rdblist.RepeatColumns = 4;

foreach (string option in options.Split(','))

ListItem items = new ListItem();
items.Text = option;
items.Value = option;




Note: In case you have any doubt in above post , you can leave your query in comment section or Email me on programmerskill@gmail.com.

Saturday, 30 April 2016

ListBox: How to Add & Delete items from ListBox in Asp.Net(c#)?

In this article we will learn how to insert and delete items from listbox control in asp.net using c#. This article is very useful for learning point of view for beginners.

Click on image to Enlarge View

Follow these steps:
   1.       Create a Website in visual studio and add a webform.
   2.       Now place one listbox control, Textbox and two buttons on webpage.
   3.        Now write the code to insert & Delete Items to Listbox on button OnClick event.

Design Section:

        <asp:ListBox ID="lstBox" runat="server" Width="150px"></asp:ListBox>
        <br />
        <br />
        <asp:TextBox ID="txtAdd" runat="server" Width="145px"></asp:TextBox>
        <br />
        <asp:Button ID="btnAdd" runat="server" Text="Add" BackColor="#009933" ForeColor="White" OnClick="btnAdd_Click" />
        <asp:Button ID="btnDelete" runat="server" Text="Delete" BackColor="#FF3300" ForeColor="White" OnClick="btnDelete_Click" />

Write code on btnAdd & btnDelete OnClick Event:

protected void btnAdd_Click(object sender, EventArgs e)
        lstBox.Items.Add(new ListItem(txtAdd.Text));
        txtAdd.Text = string.Empty;
    protected void btnDelete_Click(object sender, EventArgs e)
        List<ListItem> lstSelectedCities = new List<ListItem>();
        foreach (ListItem liItems in lstBox.Items)
            if (liItems.Selected == true)
        foreach (ListItem liSelected in lstSelectedCities)


Friday, 22 April 2016

How to Open or view Images & Docx Files in Gridview in Asp.Net (C#)?

In this article I will explain How to open or view files in gridview. While working with gridview we face a situation where we want to show filename in gridview and want to open them on click. Like given in Attached Image.
Open/View Files in Gridview(Click Image to Enlarge view)