How to create grid view in asp using c#
-------------------------Asp.aspx------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Design.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="style/bootstrap.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<div class="col-sm-12 text-center">
<asp:Label runat="server" ID="Literal1"></asp:Label></div>
<div class="row">
<div class="col-sm-12">
<table class="table-condensed table-responsive col-sm-12">
<tr>
<td class="col-sm-6">
<asp:FileUpload runat="server" ID="uploadfile" CssClass="col-sm-6 form-control" />
</td>
<td class="col-sm-6"></td>
</tr>
<tr>
<td class="col-sm-6">
<asp:Button runat="server" ID="btn_save" Text="save" CssClass="btn btn-submit col-sm-6" OnClick="btn_save_Click" />
</td>
<td><asp:Button id="btnshowgrid" CssClass="btn btn-success col-sm-6" runat="server"
Text="Show grid" onclick="btnshowgrid_Click" /></td>
</tr>
</table>
<table class="table-condensed">
<tr>
<td>
<asp:GridView runat="server" ID="GridView1">
</asp:GridView>
</td>
</tr>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Design.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="style/bootstrap.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<div class="col-sm-12 text-center">
<asp:Label runat="server" ID="Literal1"></asp:Label></div>
<div class="row">
<div class="col-sm-12">
<table class="table-condensed table-responsive col-sm-12">
<tr>
<td class="col-sm-6">
<asp:FileUpload runat="server" ID="uploadfile" CssClass="col-sm-6 form-control" />
</td>
<td class="col-sm-6"></td>
</tr>
<tr>
<td class="col-sm-6">
<asp:Button runat="server" ID="btn_save" Text="save" CssClass="btn btn-submit col-sm-6" OnClick="btn_save_Click" />
</td>
<td><asp:Button id="btnshowgrid" CssClass="btn btn-success col-sm-6" runat="server"
Text="Show grid" onclick="btnshowgrid_Click" /></td>
</tr>
</table>
<table class="table-condensed">
<tr>
<td>
<asp:GridView runat="server" ID="GridView1">
</asp:GridView>
</td>
</tr>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
-------------------------c#----------------------------
protected void btnshowgrid_Click(object sender, EventArgs e)
{
string consString = ConfigurationManager.ConnectionStrings["connectionname"].ConnectionString;
SqlConnection con = new SqlConnection(consString);
{
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from tablename", con);
{
DataTable dt = new DataTable();
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
OUTOUT:-
Comments
Post a Comment