Home > DeveloperSection > Articles > Bind Data to GridView in ASP.Net

Bind Data to GridView in ASP.Net

ASP.Net ASP.Net 
2 Comment(s)
 12894  View(s)
Rate this:

Bind Data to GridView in ASP.Net

This is my first article. In this article I have shown you how to load a GridView Using Stored Procedure.

Stored Procedure:-

create procedure usp_GetEmployeeDetails



select eid,ename,eaddress,ecity,estate from employee



<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>A Sample Program Illustrating The Data Retrieval Using Stored Procedure</title>



    <form id="form1" runat="server">


        <asp:GridView ID="GridView1" runat="server">








using System;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.Sql;

using System.Data.SqlClient;

using System.Windows.Forms;


public partial class _Default : System.Web.UI.Page


    SqlConnection conn = new SqlConnection("Data Source=INNOVA14;uid=sa;pwd=innova;Initial Catalog=Employee");

    protected void Page_Load(object sender, EventArgs e)





    public void loadmyGridUsingStoredProcedure()



        SqlDataAdapter sda = new SqlDataAdapter("usp_GetEmployeeDetails", conn);

        SqlCommand comm = new SqlCommand();

        comm.CommandType = CommandType.StoredProcedure;

        DataTable dt = new DataTable();


        GridView1.DataSource = dt;





Bind Data to GridView in ASP.Net

By Haider M Rizvi on   4 years ago

Hi Mohan Kumar,

Nice start.

Its good to see when people come forward to share their knowledge they have earned.

Suggestion: Please try to explain your code so that any one who read your article should understand the use of each line of code to accomplish the task.

Keep writing Mohan Kumar.


Thanks for your precious comment..

By mohan kumar on   4 years ago
Ya..sure Haider...

Don't want to miss updates? Please click the below button!

Follow MindStick