Create a web application to display Using Disconnected Data Access and Databinding using GridView

 8c.aspx 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="8c.aspx.cs" 

Inherits="_6A._8c" %>  

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head runat="server"> 

    <title></title> 

</head> 

<body> 

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

            <asp:Button ID="Button1" runat="server" Text="Show Disconnected fetched Data" OnClick="Button1_Click" /> 

        <br />    

        <br /> 

            <asp:GridView ID="GridView1" runat="server" Height="241px" Width="274px" 

AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" 

BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="Id" 

DataSourceID="SqlDataSource1" GridLines="Vertical"> 

                <AlternatingRowStyle BackColor="#DCDCDC" /> 

                <Columns> 

                    <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" 

SortExpression="Id" /> 

                    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> 

                    <asp:BoundField DataField="STD" HeaderText="STD" SortExpression="STD" /> 

                    <asp:BoundField DataField="Address" HeaderText="Address" 

SortExpression="Address" /> 

                    <asp:BoundField DataField="Phone No." HeaderText="Phone No." 

SortExpression="Phone No." /> 

                </Columns> 

                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" /> 

                <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" /> 

                <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> 

                <RowStyle BackColor="#EEEEEE" ForeColor="Black" /> 

                <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />                 <SortedAscendingCellStyle BackColor="#F1F1F1" /> 

                <SortedAscendingHeaderStyle BackColor="#0000A9" /> 

                <SortedDescendingCellStyle BackColor="#CAC9C9" /> 

                <SortedDescendingHeaderStyle BackColor="#000065" />             </asp:GridView> 

            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ 

ConnectionStrings:connStr %>" SelectCommand="SELECT * FROM 

[Student]"></asp:SqlDataSource>  

    </form> 

</body> 

</html> 

8c.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.SqlClient; 

using System.Data; 

using System.Configuration; 

namespace _6A 

    public partial class _8c : System.Web.UI.Page 

    { 

        SqlConnection con = new 

        SqlConnection(ConfigurationManager.ConnectionStrings["connStr"].ConnectionString);         

        protected void Page_Load(object sender, EventArgs e) 

        { 

        } 

        protected void Button1_Click(object sender, EventArgs e) 

        { 

            SqlDataAdapter da = new SqlDataAdapter(); 

            DataSet ds = new DataSet(); 

            SqlCommand cmd = new SqlCommand("Select * from Student", con); 

           cmd.CommandType = CommandType.Text; 

            da.SelectCommand = cmd; 

            da.Fill(ds); 

            GridView1.DataSource = ds.Tables[0]; 

            GridView1.DataBind(); 

        } 

    } 

Output:- 




Post a Comment

1 Comments