On this tutorial i will explain how to show data from database on gridview using asp,.net
Page: EmpList.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Configuration;
public partial class Admin2_Create_Payroll : System.Web.UI.Page
{
string ConStr;
protected void Page_Load(object sender, EventArgs e)
{
DisplayEmp();
}
public void DisplayEmp()
{
try
{
ConStr = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
//SqlDataAdapter Adp = new SqlDataAdapter();
SqlDataAdapter Adp = new SqlDataAdapter("select * from employees", ConStr);
DataTable Dt = new DataTable();
Adp.Fill(Dt);
if (Dt.Rows.Count > 0)
{
GvEmployee.DataSource = Dt;
GvEmployee.DataBind();
}
}
catch(Exception ex)
{
}
}
}
Page: Emplist.aspx.cs
<%@ Page Title="" Language="C#" AutoEventWireup="true" CodeFile="EmpList.aspx.cs" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div class="panel-body col-sm-12">
<div class="panel panel-default" style="min-height:200px">
<asp:GridView ID="GvEmployee" runat="server"></asp:GridView>
</div>
</div>
</asp:Content>