Default.aspx file
<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master"
CodeBehind="Default.aspx.cs" Inherits="ShowDataOnePage2010._Default" %>
<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;">
RegiRegistration Form</td>
</tr>
<tr>
<td>
RegistrationID :>
<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="Submit_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>Sex :</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>
Default.aspx.cs file
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 btnSave_Click(object sender, EventArgs e)
{
string Sex;
if(radioMale.Checked==true)
{
Sex="Male";
}
else
{
Sex="Female";
}
foreach(ListItem li in CheckBoxList1.Items)
{
if(li.Selected==true)
{
Course += li.Text + ",";
}
}
string StrCon = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection SqlConn = new SqlConnection(StrCon);
string SqlQuery = "Insert into ShowOnePage(RegistrationId,Name,Address,MobileNo,Course,Sex,EmailID) values"
+"('" + txtRegistrationId.Text + "','" + txtName.Text + "','" + txtAddress.Text + "'," + txtMobileNo.Text + ",'" + Course + "','" + Sex + "','" + txtEmailId.Text + "')";
SqlCommand SqlComm = new SqlCommand(SqlQuery, SqlConn);
SqlConn.Open();
int RecordsAffected;
RecordsAffected = SqlComm.ExecuteNonQuery();
if (RecordsAffected > 0)
{
lblMsg.Text = "Records are insert Successfully";
}
else
{
lblMsg.Text = "No Records Inserted";
//Timer1.Enabled = true;
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
string Sex;
if (radioMale.Checked == true)
{
Sex = "Male";
}
else
{
Sex = "Female";
}
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected == true)
{
Course += li.Text + ",";
}
}
string StrCon = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection SqlConn = new SqlConnection(StrCon);
string SqlQuery = "Update ShowOnePage set Name='" + txtName.Text + "',Address='" + txtAddress.Text + "',MobileNo=" + txtMobileNo.Text + ",Course='" + Course + "',Sex='" + Sex + "',EmailID='" + txtEmailId.Text + "' where RegistrationId='" + txtRegistrationId.Text + "'";
SqlCommand SqlComm = new SqlCommand(SqlQuery, SqlConn);
SqlConn.Open();
int RecordsAffected;
RecordsAffected = SqlComm.ExecuteNonQuery();
if (RecordsAffected > 0)
{
lblMsg.Text = "Records are update Successfully";
}
else
{
lblMsg.Text = "No Records Updated";
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
string StrCon = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection SqlConn = new SqlConnection(StrCon);
string SqlQuery = "Delete from ShowOnePage where RegistrationId='" + txtRegistrationId.Text + "'";
SqlCommand SqlComm = new SqlCommand(SqlQuery, SqlConn);
SqlConn.Open();
int RecordsAffected;
RecordsAffected = SqlComm.ExecuteNonQuery();
if (RecordsAffected > 0)
{
lblMsg.Text = "Records are Delete Successfully";
}
else
{
lblMsg.Text = "No Records Deleted";
}
}
protected void btnShow_Click(object sender, EventArgs e)
{
string StrCon = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection SqlConn = new SqlConnection(StrCon);
string SqlQuery = "Select * from ShowOnePage";
SqlCommand SqlComm = new SqlCommand(SqlQuery, SqlConn);
SqlConn.Open();
SqlDataReader dr;
dr = SqlComm.ExecuteReader(CommandBehavior.CloseConnection);
GridView1.DataSource = dr;
GridView1.DataBind();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string Sex;
if (radioMale.Checked == true)
{
Sex = "Male";
}
else
{
Sex = "Female";
}
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected == true)
{
Course += li.Text + ",";
}
}
string StrCon = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection SqlConn = new SqlConnection(StrCon);
string SqlQuery = "Select Name,Address,MobileNo,Course,Sex,EmailID from ShowOnePage where RegistrationId='" + txtRegistrationId.Text + "'";
SqlCommand SqlComm = new SqlCommand(SqlQuery, SqlConn);
SqlConn.Open();
SqlDataReader dr;
dr = SqlComm.ExecuteReader(CommandBehavior.CloseConnection);
while (dr.Read())
{
//txtRegistrationId.Text = dr["RegistrationId"].ToString();
txtName.Text = dr["Name"].ToString();
txtAddress.Text = dr["Address"].ToString();
txtMobileNo.Text = dr["MobileNo"].ToString();
Course = dr["Course"].ToString();
Sex = dr["Sex"].ToString();
txtEmailId.Text = dr["EmailID"].ToString();
lblMsg2.Text = dr["Course"].ToString();
lblSex.Text = dr["Sex"].ToString();
}
}
}
}
<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master"
CodeBehind="Default.aspx.cs" Inherits="ShowDataOnePage2010._Default" %>
<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;">
RegiRegistration Form</td>
</tr>
<tr>
<td>
RegistrationID :>
<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="Submit_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>Sex :</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>
Default.aspx.cs file
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 btnSave_Click(object sender, EventArgs e)
{
string Sex;
if(radioMale.Checked==true)
{
Sex="Male";
}
else
{
Sex="Female";
}
foreach(ListItem li in CheckBoxList1.Items)
{
if(li.Selected==true)
{
Course += li.Text + ",";
}
}
string StrCon = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection SqlConn = new SqlConnection(StrCon);
string SqlQuery = "Insert into ShowOnePage(RegistrationId,Name,Address,MobileNo,Course,Sex,EmailID) values"
+"('" + txtRegistrationId.Text + "','" + txtName.Text + "','" + txtAddress.Text + "'," + txtMobileNo.Text + ",'" + Course + "','" + Sex + "','" + txtEmailId.Text + "')";
SqlCommand SqlComm = new SqlCommand(SqlQuery, SqlConn);
SqlConn.Open();
int RecordsAffected;
RecordsAffected = SqlComm.ExecuteNonQuery();
if (RecordsAffected > 0)
{
lblMsg.Text = "Records are insert Successfully";
}
else
{
lblMsg.Text = "No Records Inserted";
//Timer1.Enabled = true;
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
string Sex;
if (radioMale.Checked == true)
{
Sex = "Male";
}
else
{
Sex = "Female";
}
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected == true)
{
Course += li.Text + ",";
}
}
string StrCon = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection SqlConn = new SqlConnection(StrCon);
string SqlQuery = "Update ShowOnePage set Name='" + txtName.Text + "',Address='" + txtAddress.Text + "',MobileNo=" + txtMobileNo.Text + ",Course='" + Course + "',Sex='" + Sex + "',EmailID='" + txtEmailId.Text + "' where RegistrationId='" + txtRegistrationId.Text + "'";
SqlCommand SqlComm = new SqlCommand(SqlQuery, SqlConn);
SqlConn.Open();
int RecordsAffected;
RecordsAffected = SqlComm.ExecuteNonQuery();
if (RecordsAffected > 0)
{
lblMsg.Text = "Records are update Successfully";
}
else
{
lblMsg.Text = "No Records Updated";
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
string StrCon = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection SqlConn = new SqlConnection(StrCon);
string SqlQuery = "Delete from ShowOnePage where RegistrationId='" + txtRegistrationId.Text + "'";
SqlCommand SqlComm = new SqlCommand(SqlQuery, SqlConn);
SqlConn.Open();
int RecordsAffected;
RecordsAffected = SqlComm.ExecuteNonQuery();
if (RecordsAffected > 0)
{
lblMsg.Text = "Records are Delete Successfully";
}
else
{
lblMsg.Text = "No Records Deleted";
}
}
protected void btnShow_Click(object sender, EventArgs e)
{
string StrCon = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection SqlConn = new SqlConnection(StrCon);
string SqlQuery = "Select * from ShowOnePage";
SqlCommand SqlComm = new SqlCommand(SqlQuery, SqlConn);
SqlConn.Open();
SqlDataReader dr;
dr = SqlComm.ExecuteReader(CommandBehavior.CloseConnection);
GridView1.DataSource = dr;
GridView1.DataBind();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string Sex;
if (radioMale.Checked == true)
{
Sex = "Male";
}
else
{
Sex = "Female";
}
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected == true)
{
Course += li.Text + ",";
}
}
string StrCon = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection SqlConn = new SqlConnection(StrCon);
string SqlQuery = "Select Name,Address,MobileNo,Course,Sex,EmailID from ShowOnePage where RegistrationId='" + txtRegistrationId.Text + "'";
SqlCommand SqlComm = new SqlCommand(SqlQuery, SqlConn);
SqlConn.Open();
SqlDataReader dr;
dr = SqlComm.ExecuteReader(CommandBehavior.CloseConnection);
while (dr.Read())
{
//txtRegistrationId.Text = dr["RegistrationId"].ToString();
txtName.Text = dr["Name"].ToString();
txtAddress.Text = dr["Address"].ToString();
txtMobileNo.Text = dr["MobileNo"].ToString();
Course = dr["Course"].ToString();
Sex = dr["Sex"].ToString();
txtEmailId.Text = dr["EmailID"].ToString();
lblMsg2.Text = dr["Course"].ToString();
lblSex.Text = dr["Sex"].ToString();
}
}
}
}
Web Config File
<configuration>
<appSettings>
<add key="ConnectionString" value="Server=PRADEEP-HP;Database=Decofloore2;User Id=User_006;password=user006"/>
</appSettings>
</configuration>
hi this is good for me....
ReplyDelete