Total Pageviews

2 May 2012

How show value in grid view in ASP.net

About.aspx=>
<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="About.aspx.cs" Inherits="About" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:GridView ID="GridView1" runat="server"
        >
    </asp:GridView>
</asp:Content>
About.aspx.cs=>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
public partial class About : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    string s = ConfigurationManager.ConnectionStrings["conn"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        con = new SqlConnection(s);
       if (!IsPostBack)
        {
            BindGridView();
        }
    }
    public void BindGridView()
    {
        SqlDataAdapter ad = new SqlDataAdapter("select * from Employees order by EmployeeID", con);
        DataSet ds = new DataSet(); ad.Fill(ds);
        GridView1.DataSource = ds; GridView1.DataBind();
    }

   
}

No comments:

Post a Comment

Contact Form

Name

Email *

Message *