<%@ Page Language="C#"
AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(document).ready(function()
{
$("#Label20").fadeOut();
$("#Label19").fadeOut();
$("#Label20").fadeIn();
$("#Label19").fadeIn();
});
</script>
<script>
function
zoomin(obj) {
$(obj).css("cursor",
"pointer");
$(obj).animate({ width: "300px" }, 'normal');
//$(obj).animate({
height: "50px" }, 'normal');
}
function
zoomout(obj) {
$(obj).animate({ width: "200px" }, 'normal');
//$(obj).animate({
height: "20px" }, 'normal');
}
</script>
<script>
$(document).ready(function()
{
$("#Label20").click(function() {
$("#t").show();
});
});
</script>
<script>
$(document).ready(function()
{
//changecolor();
//changecolor1();
changecolor2();
changecolor3();
});
</script>
<script>
$(document).ready(function()
{
$("#Label19").click(function() {
$("#t").hide();
var gr = $("#GridView1");
gr.animate({ height: '1000px', opacity: '0.4'
}, "slow");
gr.animate({ width: '1000px', opacity: '0.8'
}, "slow");
//gr.animate({
height: '500px', opacity: '0.4' }, "slow");
//gr.animate({
width: '500px', opacity: '0.8' }, "slow");
gr.animate({ fontSize: '3em' }, "slow");
gr.animate({ fontSize: '1em' }, "slow");
gr.animate({ height: '300px' }, "slow");
gr.animate({ width: '300px' }, "slow");
});
});
function
changecolor() {
var
colors = ["#00FF00", "#CCCCCC", "#3399CC","#990099", "#FEA400",
"#FF9900", "#6600FF", "#333333",
];
var
rand = Math.floor(Math.random() * colors.length);
$('#GridView1').css("background-color", colors[rand]);
setTimeout('changecolor()',
1000);
}
function
changecolor1() {
var
colors = ["#00FF00", "#CCCCCC","#3399CC","#990099", "#FEA400",
"#FF9900", "#6600FF", "#333333",
];
var
rand = Math.floor(Math.random() * colors.length);
$('#t').css("background-color", colors[rand]);
setTimeout('changecolor1()',
1000);
}
function
changecolor2() {
var
colors = ["#00FF00", "#CCCCCC", "#3399CC",
"blue", "pink",
"white", "#990099",
"#FEA400", "#FF9900", "#6600FF",
"#333333", ];
var
rand = Math.floor(Math.random() * colors.length);
$('#Label20').css("background-color", colors[rand]);
setTimeout('changecolor2()',
500);
}
function
changecolor3() {
var
colors = ["#00FF00", "#CCCCCC", "#3399CC","red","blue","pink","white",
"#990099", "#FEA400", "#FF9900",
"#6600FF", "#333333", ];
var
rand = Math.floor(Math.random() * colors.length);
$('#Label19').css("background-color", colors[rand]);
setTimeout('changecolor3()',
700);
}
</script>
</head>
<body bgcolor="#3399CC">
<form id="form1" runat="server">
<img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgURn5bJiiQhPLm53keH-M46RAYsOndTVZOdGw-83EUQDCVr16UTl6QnlT6AgQrJbgCj9032xXdfEjkQDtrEqr04potpYBrDZwBMvYjKbVY9ScMur-uLEn5g8zFTJfPVGlpR31e7WNR0j8/s1600/Smiley.png"
width="200"
alt="smile"
id="imgSmile"
onmouseover="zoomin(this)" onmouseout="zoomout(this)" />
<table id="t" border="1" bordercolor="white" >
<tr>
<td>
<h1 class="stylee">REGISTER
FORM</h1>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" ForeColor="White"
runat="server"
Text="employee
name"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
</td><td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ErrorMessage="please
enter company name" ForeColor="Blue"
ControlToValidate="TextBox1">
</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" ForeColor="White"
runat="server"
Text="employee
address"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2"
runat="server"
TextMode="MultiLine"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2"
runat="server"
ErrorMessage="please
enter company address" ForeColor="Blue"
ControlToValidate="TextBox2"
> </asp:RequiredFieldValidator></td>
</tr>
<%--<tr>
<td>
<asp:Label
ID="Label3" ForeColor="White" runat="server"
Text="company man_address"></asp:Label>
</td>
<td>
<asp:TextBox
ID="TextBox3" runat="server"
TextMode="MultiLine"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3"
runat="server" ErrorMessage="please enter company address"
ForeColor="Blue"
ControlToValidate="TextBox2" >
</asp:RequiredFieldValidator></td>
</tr>--%>
<tr>
<td>
<asp:Label ID="Label4" ForeColor="White"
runat="server"
Text="employee
state"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1"
runat="server"
style="height:
22px"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True"
DataTextField="statename"
DataValueField="statename"
>
</asp:DropDownList>
<td>
<%--<asp:RequiredFieldValidator
ID="RequiredFieldValidator8" runat="server"
ErrorMessage="please enter company address" ForeColor="Red"
ControlToValidate="TextBox4" >
</asp:RequiredFieldValidator></td>--%>
</tr>
<tr>
<td>
<asp:Label ID="Label5" ForeColor="White"
runat="server"
Text="employee
city"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList2"
runat="server"
AutoPostBack="True"
DataTextField="city"
DataValueField="city"
>
</asp:DropDownList>
</td>
<td>
<%--<asp:RequiredFieldValidator ID="RequiredFieldValidator4"
runat="server" ErrorMessage="please enter city"
ForeColor="Red"
ControlToValidate="TextBox5" >
</asp:RequiredFieldValidator></td>--%>
</tr>
<tr>
<td>
<asp:Label ID="Label6" ForeColor="White"
runat="server"
Text="employee
email"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox6"
runat="server"></asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1"
runat="server"
ForeColor="Blue"
ErrorMessage="invalid
email" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ControlToValidate="TextBox6">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label7" ForeColor="White"
runat="server"
Text="employee
salary"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox7"
runat="server"
></asp:TextBox>
</td>
<td>
<%--<asp:RegularExpressionValidator
ID="RegularExpressionValidator2" runat="server"
ValidationExpression="http(s)?://([\w-]+\.)+[\w-]+(/[\w-
./?%&=]*)?"
ForeColor="Blue" ControlToValidate="TextBox7" ErrorMessage="Input valid Internet
URL!">
</asp:RegularExpressionValidator>--%>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label14"
ForeColor="White"
runat="server"
Text="employee
photos"></asp:Label>
</td>
<td>
<asp:FileUpload ID="FileUpload1"
runat="server"
/>
</td>
<td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator8"
runat="server"
ErrorMessage="enter
logo" ForeColor="Blue" ControlToValidate="FileUpload1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server"
ForeColor="White"
Text="Gender"></asp:Label>
</td>
<td>
<%--<asp:RadioButtonList ForeColor="White"
ID="RadioButtonList1" runat="server">
<asp:ListItem Text="male"
Value="0"></asp:ListItem>
<asp:ListItem
Text="female" Value="1"></asp:ListItem>
</asp:RadioButtonList>--%>
<asp:RadioButton ID="RadioButton1" ForeColor="White" Text="male" runat="server" GroupName="x" />
<asp:RadioButton ID="RadioButton2"
ForeColor="White"
Text="female"
runat="server"
GroupName="x"
/>
</td>
<td>
<%--<asp:RequiredFieldValidator
ID="RequiredFieldValidator3"
runat="server" ErrorMessage="please check Gender"
ControlToValidate="RadioButtonList1"></asp:RequiredFieldValidator>--%>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label8" runat="server" ForeColor="White" Text="Hobbys"></asp:Label>
</td>
<td>
<asp:CheckBoxList ForeColor="White"
ID="CheckBoxList1"
runat="server">
<asp:ListItem Text="Reading
book"></asp:ListItem>
<asp:ListItem Text="coock"></asp:ListItem>
<asp:ListItem Text="watch
movie"></asp:ListItem>
</asp:CheckBoxList>
</td>
<%--<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4"
runat="server" ErrorMessage="please checked hobbys"
ControlToValidate="CheckBoxList1"></asp:RequiredFieldValidator>
</td>--%>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="Button1"
runat="server"
Text="insert"
onclick="Button1_Click"
/>
<asp:Button ID="Button2"
runat="server"
Text="update"
CausesValidation="False"
onclick="Button2_Click"
Visible="false"
/>
<asp:Button ID="Button3"
runat="server"
Text="Cleare"
CausesValidation="False"
onclick="Button3_Click"
/>
</td>
</tr>
</table>
<asp:Label ID="Label19" onmouseover="zoomin(this)" onmouseout="zoomout(this)" BackColor="Red" Width="120px" runat="server"
Text="show gridview" Height="20px"></asp:Label>
<asp:Label ID="Label20" BackColor="Red" Width="120px" runat="server"
Text="show Table" onmouseover="zoomin(this)" onmouseout="zoomout(this)" Height="20px"></asp:Label>
<br />
<asp:GridView ID="GridView1" ForeColor="White" runat="server" DataKeyNames="emp_id"
AutoGenerateColumns="False" onrowediting="GridView1_RowEditing"
onrowdeleting="GridView1_RowDeleting" >
<Columns>
<asp:TemplateField HeaderText="id" Visible="false">
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%#Eval("emp_id")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="emp_nm">
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%#Eval("emp_nm")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="emp_add">
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%#Eval("emp_add")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="state">
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%#Eval("state")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="city">
<ItemTemplate>
<asp:Label ID="Label13" runat="server" Text='<%#Eval("city")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="emp_email">
<ItemTemplate>
<asp:Label ID="Label14" runat="server" Text='<%#Eval("emp_email")
%>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="emp_salary">
<ItemTemplate>
<asp:Label ID="Label15" runat="server" Text='<%#Eval("emp_salary")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="emp_nm">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Width="60px"
Height="60px"
ImageUrl='<%#Eval("emp_photo")%>' />
<asp:Label ID="Label18" runat="server" Text='<%#Eval("emp_photo")
%>' Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="gender">
<ItemTemplate>
<asp:Label ID="Label16" runat="server" Text='<%#Eval("gender")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="hobby">
<ItemTemplate>
<asp:Label ID="Label17" runat="server" Text='<%#Eval("hobby")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="edit">
<ItemTemplate>
<%--<asp:LinkButton
ID="LinkButton1" runat="server" OnClick=edit
CausesValidation="False">edit</asp:LinkButton>--%>
<asp:LinkButton ID="LinkButton1" CommandName="edit" CausesValidation="false" runat="server">edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="delete">
<ItemTemplate>
<%--<asp:LinkButton
ID="LinkButton2" OnClick="delete"
CausesValidation="false"
runat="server">delete</asp:LinkButton>--%>
<asp:LinkButton ID="LinkButton2" CausesValidation="false" CommandName="delete" runat="server">delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
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.IO;
using
System.Collections;
public partial class _Default : System.Web.UI.Page
{
DataClassesDataContext
dc = new DataClassesDataContext();
protected void Page_Load(object
sender, EventArgs e)
{
grid();
if
(!IsPostBack)
{
Bind_ddlstate();
}
}
public void Bind_ddlstate()
{
var
emps = from myemp in
dc.pi_statedemos
select
new
{
myemp.statename
};
DropDownList1.DataSource = emps;
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("--select--"));
//
DropDownList2.Items.Insert(0, new ListItem("--select--"));
//if
(DropDownList1.SelectedIndex == -1)
//{
// DropDownList2.SelectedIndex = -1;
//}
}
public void Bind_ddlCity()
{
int i =
DropDownList1.SelectedIndex;
DropDownList2.Items.Clear();
var
emps = from myemp in
dc.pi_citydemos
where
myemp.id == i
select
new
{
myemp.city
};
DropDownList2.DataSource = emps;
DropDownList2.DataBind();
}
public void grid()
{
var
emps = from myemp in
dc.pi_emps
select
myemp;
GridView1.DataSource = emps;
GridView1.DataBind();
}
protected void Button1_Click(object
sender, EventArgs e)
{
FileUpload1.SaveAs(Server.MapPath("~/image/")+FileUpload1.FileName);
string
s ="~/image/"+FileUpload1.FileName;
string
g=null;
string
s1 = string.Empty;
if
(RadioButton1.Checked)
{
g = RadioButton1.Text;
}
else
{
g = RadioButton2.Text;
}
foreach
(ListItem item in
this.CheckBoxList1.Items)
{
if
(item.Selected)
{
s1 += item+"," ;
}
}
using
(DataClassesDataContext dd = new DataClassesDataContext())
{
dd.pi_insert(TextBox1.Text,TextBox2.Text,DropDownList1.SelectedValue,DropDownList2.SelectedValue,TextBox6.Text,int.Parse(TextBox7.Text),s,g,s1);
}
TextBox1.Text = "";
TextBox2.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
DropDownList1.SelectedIndex =- 1;
Bind_ddlCity();
RadioButton1.Checked = false;
RadioButton2.Checked = false;
Button2.Visible = false;
grid();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs
e)
{
Bind_ddlCity();
}
protected void GridView1_RowEditing(object
sender, GridViewEditEventArgs e)
{
Label
id = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label9");
Session["id"]
= id.Text;
Label
nm = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label10");
TextBox1.Text = nm.Text;
Label
add = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label11");
TextBox2.Text = add.Text;
Label
st = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label12");
DropDownList1.SelectedValue = st.Text;
Bind_ddlCity();
//Label ct =
(Label)GridView1.Rows[e.NewEditIndex].FindControl("Label13");
//DropDownList2.SelectedValue
= ct.Text;
Label
em = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label14");
TextBox6.Text = em.Text;
Label
sa = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label15");
TextBox7.Text = sa.Text;
Label
ph = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label18");
Session["ph"]
= ph.Text;
Label
g = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label16");
if
(g.Text.Equals("male"))
{
RadioButton1.Checked = true;
}
else
{
RadioButton2.Checked = true;
}
Label
ho = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label17");
foreach
(ListItem li in
CheckBoxList1.Items)
{
if
(ho.Text.Contains(li.Text))
{
li.Selected = true;
}
}
Button1.Visible = false;
Button2.Visible = true;
Button3.Visible = false;
//Label nm =
(Label)GridView1.Rows[e.NewEditIndex].FindControl("Label9");
}
protected void GridView1_RowDeleting(object
sender, GridViewDeleteEventArgs e)
{
Session["b"]
= GridView1.DataKeys[e.RowIndex].Value.ToString();
/*var emp =
dc.pi_emps.Single(myemp => myemp.emp_id ==
int.Parse(Session["b"].ToString()));
dc.pi_emps.DeleteOnSubmit(emp);
try
{
dc.SubmitChanges();
Response.Write("Deleted");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}*/
dc.pi_delete(int.Parse(Session["b"].ToString()));
grid();
}
protected void
Button2_Click(object sender, EventArgs e)
{
string
s = null;
if
(FileUpload1.HasFile)
{
FileUpload1.SaveAs(Server.MapPath("~/image/") + FileUpload1.FileName);
s = "~/image/"
+ FileUpload1.FileName;
}
else
{
s = Session["ph"].ToString();
}
string
g = null;
string
s1 = string.Empty;
if
(RadioButton1.Checked)
{
g = RadioButton1.Text;
}
else
{
g = RadioButton2.Text;
}
foreach
(ListItem item in
this.CheckBoxList1.Items)
{
if
(item.Selected)
{
s1 += item + ",";
}
}
using (DataClassesDataContext dd = new DataClassesDataContext())
{
//var emp
= (from ed in dd.pi_emps where ed.emp_id ==
int.Parse(Session["id"].ToString()) select ed);
dd.pi_update(int.Parse(Session["id"].ToString()),TextBox1.Text,
TextBox2.Text, DropDownList1.SelectedValue, DropDownList2.SelectedValue,
TextBox6.Text, int.Parse(TextBox7.Text), s, g,
s1);
}
Button2.Visible = false;
Button3.Visible = true;
Button1.Visible = true;
TextBox1.Text = "";
TextBox2.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
DropDownList1.SelectedIndex = -1;
Bind_ddlCity();
RadioButton1.Checked = false;
RadioButton2.Checked = false;
grid();
}
protected void Button3_Click(object
sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
DropDownList1.SelectedIndex = -1;
Bind_ddlCity();
RadioButton1.Checked = false;
RadioButton2.Checked = false;
}
}
0 comments :