Click here to Skip to main content
15,886,541 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CS Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WebForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
ConnectionClass obj = new ConnectionClass();
obj.Connection();
obj.cmd.CommandText = "sp_getstudentdata";
obj.con.Open();
obj.dr = obj.cmd.ExecuteReader();
if (obj.dr.HasRows)
{
this.GridView1.DataSource = obj.dr;
this.GridView1.DataBind();
}
else
{
Response.Write("No Data Found");
}
obj.dr.Close();
obj.con.Close();

}
}

HTML CODE



<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
&nbsp;<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<br />
<br />
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>

</div>
</form>
</body>
</html>

Connection Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

///
/// Summary description for ConnectionClass
///

public class ConnectionClass
{
public SqlConnection con;
public SqlCommand cmd;
public SqlDataReader dr;

public void Connection()
{
SqlConnection con = new SqlConnection("Data source=ASHOK-PC;integrated security=true;initial catalog=db");
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
}



}
Posted

1 solution

modify the sqlconnection .also set the username and password of your db
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900