*These namespaces
are must be required for SqlServer Connectivity in your web form:-
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
Default.aspx
<%@ 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;">
Registration 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>Gender
:</b><asp:Label ID="lblSex" runat="server" Font-Bold="True"></asp:Label>
</td>
</tr>
<tr>
<td>
Email ID
<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>
Default.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 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 + "',Gender='" + 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";
}
}
}
}
0 comments
Post a Comment