How to display data in grid view

March 21, 2013 |

DISPLAYSTUDENT.ASPX.CS

using System;
using System.Collections;
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.SqlClient;
public partial class DisplayUsers : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            SqlConnection con = new SqlConnection(DataBase.connect);
            SqlDataAdapter da = new SqlDataAdapter("select * from Stud_Info", con);
            SqlCommandBuilder cm = new SqlCommandBuilder(da);
            DataSet ds = new DataSet();
            da.Fill(ds, "Stud_Info");
            if (ds.Tables["Stud_Info"].Rows.Count > 0)
            {
                GridView1.DataSource = ds.Tables["Stud_Info"];
                GridView1.DataBind();
            }
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
      
    }
}

DISPLAYSTUDENT.ASPX

<%@ Page Language="C#" MasterPageFile="~/Hostel.master" AutoEventWireup="true" CodeFile="DisplayStudent.aspx.cs" Inherits="DisplayUsers" Title="DisplayStudent" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            height: 16px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  
    <table class="style1">
        <tr>
            <td align="center" colspan="2">
                <asp:Label ID="Label1" runat="server" Text="Student Details" Font-Size="Medium"></asp:Label>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style2" colspan="2">
                <asp:Panel ID="Panel1" runat="server" ScrollBars="Both" Height="471px"
                    Width="682px">
                    <asp:GridView ID="GridView1" runat="server" BackColor="White"
                        BorderColor="#CC9966" BorderStyle="None"
                        BorderWidth="1px" CellPadding="4"
                        Height="467px" Width="682px"
                           onselectedindexchanged="GridView1_SelectedIndexChanged">
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                        <FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <EditRowStyle BackColor="#999999" />
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    </asp:GridView>
                </asp:Panel>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Back"
                    Width="151px" />
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
   
</asp:Content>





Student Details
 
Stud_IDStud_NameStud_YearStud_AddressStud_CityStud_StateStud_CountryStud_EmailHostelStud_PhoneStud_FeeEntry_DateExit_DateStud_RoomF_EID
500006101Koyyana Venkata SarthakFirstAzad NagarDelhiDelhiIndiakoyyana@ymail.comBravo9050383232Paid3/8/2013 12:00:00 AM3/20/2013 12:00:00 AM45ter@gmail.com
500012328Partha MehrotraSecond New Model townAssamAssamIndiapartha@gmail.comBravo9876543212Paid3/12/2013 12:00:00 AM3/21/2013 12:00:00 AM09gmail@gmail.com
500012717Kshitij DeopaThirdModeltownPanipatHaryanaIndiadeopa@gmail.comBravo9823456654Paid3/7/2013 12:00:00 AM3/18/2013 12:00:00 AM88 
500017072Sachin AgarwalSecondH.No 465 Kirti NagarDelhiDelhiIndiasachin@gmai.comAlpha9723454345Pending  13sachin@gmail.com
500543250SumitFirstPanipatpanipatharyanaSri Lankaesh@gmail.comAlpha3214509876Pending3/14/2013 12:00:00 AM 23 
500543255SumitFirstPanipatpanipatharyanaSri Lankaesh@gmail.comAlpha3214509876Pending3/14/2013 12:00:00 AM 23 
500564399YogeshSecondPanipatpanipatharyanaChinaes@gmail.comCharlie9070575432Pending3/12/2013 12:00:00 AM 45 
500959312RohitFirstDelhiDelhiDelhiIndiarohit@gmail.comDelta9896092048Paid2/25/2013 12:00:00 AM 32 
505967521AnilFirstDelhiDelhiHaryanaIndiaanil@gmail.comAlpha9896097048Pending3/13/2013 12:00:00 AM3/22/2013 12:00:00 AM10 
 

0 comments:

Post a Comment