Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> ASP.Net & Web Forms >> Bind Data to GridView in ASP.Net
Bind Data to GridView in ASP.Net
Bind Data to GridView in ASP.Net


by mohan kumar on 11/3/2011 6:12:47 PM

Views: 2253       Comments: 2

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

as

begin

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

end

Default.aspx:-

<%@ 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>

</head>

<body>

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

    <div>

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

        </asp:GridView>

    </div>

    </form>

</body>

</html>

 

Default.aspx.cs

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)

    {

        loadmyGridUsingStoredProcedure();

    }

 

    public void loadmyGridUsingStoredProcedure()

    {

        conn.Open();

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

        SqlCommand comm = new SqlCommand();

        comm.CommandType = CommandType.StoredProcedure;

        DataTable dt = new DataTable();

        sda.Fill(dt);

        GridView1.DataSource = dt;

        GridView1.DataBind();

        conn.Close();

    }

}

Report Abuse Form
Reason:    
 


Bind Data to GridView in ASP.Net
by Haider M Rizvi 11/4/2011 8:34:20 AM

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

Report Abuse

Thanks for your precious comment..
by mohan kumar 11/10/2011 1:06:12 AM
Ya..sure Haider...
Report Abuse
Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by mohan kumarRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 4227
Advertisement
MindStick DataConver
Advertise with Us
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.