*These
namespaces are must be required for SqlServer Connectivity in your web form:-
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
Default3.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default3.aspx.cs" Inherits="ShowDataOnePage2010.Default3" MasterPageFile="~/Site.Master" %>
<asp:Content ID="Content1" runat="server" contentplaceholderid="MainContent">
<table class="style1">
<tr>
<td align="center" colspan="4"
style="font-family: Georgia; font-size: small; font-weight: bold; color: #800000;">
Registration Form</td>
</tr>
<tr>
<td>
RegistrationID :</td>
<td>
<asp:TextBox ID="txtRegistrationId" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnSubmit" runat="server" BackColor="#CCCCCC" Font-Bold="True"
onclick="btnSubmit_Click" Text="User_ID" />
</td>
<td>
</td>
</tr>
<tr>
<td>
Name :</td>
<td class="style2">
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Address :</td>
<td class="style2">
<asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Mobile No :</td>
<td class="style2">
<asp:TextBox ID="txtMobileNo" runat="server"></asp:TextBox>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Course :</td>
<td class="style2">
<asp:CheckBoxList ID="CheckBoxList1" runat="server" Font-Bold="True">
<asp:ListItem>MCA</asp:ListItem>
<asp:ListItem>MBA</asp:ListItem>
<asp:ListItem>B.Tech</asp:ListItem>
<asp:ListItem>CA</asp:ListItem>
</asp:CheckBoxList>
<b>Course :</b>
<asp:Label ID="lblMsg2" runat="server" Font-Bold="True"></asp:Label>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Sex :</td>
<td class="style2">
<asp:RadioButton ID="radioMale" runat="server" Font-Bold="True" GroupName="sex"
Text="Male" />
</td>
<td>
<asp:RadioButton ID="radioFemale" runat="server" Font-Bold="True"
GroupName="sex" Text="Female" />
</td>
<td>
<b>Gender :</b><asp:Label ID="lblSex" runat="server" Font-Bold="True"></asp:Label>
</td>
</tr>
<tr>
<td>
Email ID</td>
<td class="style2">
<asp:TextBox ID="txtEmailId" runat="server"></asp:TextBox>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td colspan="4">
<asp:Label ID="lblMsg" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td colspan="4">
<asp:GridView ID="GridView1" runat="server" PageSize="3" CellPadding="4"
ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="btnSave" runat="server" BackColor="#CCCCCC" Font-Bold="True"
Text="Save" onclick="btnSave_Click" />
</td>
<td align="center" class="style2">
<asp:Button ID="btnUpdate" runat="server" BackColor="#CCCCCC" Font-Bold="True"
Text="Update" onclick="btnUpdate_Click" />
</td>
<td align="center">
<asp:Button ID="btnDelete" runat="server" BackColor="#CCCCCC" Font-Bold="True"
Text="Delete" onclick="btnDelete_Click" />
</td>
<td align="center">
<asp:Button ID="btnShow" runat="server" BackColor="#CCCCCC" Font-Bold="True"
Text="Show" onclick="btnShow_Click" />
</td>
</tr>
</table>
</asp:Content>
<asp:Content ID="Content2" runat="server" contentplaceholderid="HeadContent">
<style type="text/css">
.style1
{
width: 522px;
margin-left: 243px;
}
</style>
</asp:Content>
Web.Config File
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="ConnectionString" value="Server=PRADEEP-HP;Database=Decofloore2;User
Id=User_006;password=user006"/>
</appSettings>
</configuration>
Default3.aspx.cs Page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace ShowDataOnePage2010
{
public partial class _Default : System.Web.UI.Page
{
string Course;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
lblMsg.Text = "";
}
}
protected void btnShow_Click(object sender, EventArgs e)
{
string StrCon = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection SqlConn = new SqlConnection(StrCon);
string SqlQuery = "Select
* from ShowOnePage";
SqlDataAdapter da = new SqlDataAdapter(SqlQuery, SqlConn);
DataTable dt = new DataTable("ShowOnePage");
da.Fill(dt);
SqlConn.Open();
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
0 comments
Post a Comment