Total Pageviews

7 May 2012

How show value in Grid view in ASP.Net


<%@ 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>
/////////////////////////////////
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();
    }

   
}

2 comments:

  1. good job dear .......plz give the definition of web server and their functionality.........Raghu MCA

    ReplyDelete
  2. A Web server is a program that using the clientserver model and the World Wide Webs Hypertext Transfer Protocol HTTP serves the files that form Web.

    ReplyDelete

Contact Form

Name

Email *

Message *