查看,写入,修改一个页面:
<%@ 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>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
}
.style3
{
}
.style6
{
}
.style7
{
width: 94px;
}
.style9
{
height: 26px;
}
.style10
{
width: 4px;
height: 26px;
}
.style11
{
width: 94px;
height: 26px;
}
.style12
{
width: 24px;
}
.style13
{
}
.style15
{
width: 4px;
}
.style16
{
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="width: 1003px; margin:0 auto; height: 1321px;">
<table id="tabledisp" runat="server" class="style1" style="border: thin solid #008000">
<tr>
<td colspan="2" style="border: thin solid #C0C0C0">
姓 名
</td>
<td colspan="7" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
<td class="style15" style="border: thin solid #C0C0C0">
性别</td>
<td style="border: thin solid #C0C0C0">
<asp:RadioButton ID="sex" runat="server" GroupName="0" Text="男"
Checked="True" />
<asp:RadioButton ID="sex0" runat="server" GroupName="0" Text="女" />
</td>
<td class="style7" style="border: thin solid #C0C0C0">
出生日期</td>
<td style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtbrithday" runat="server"></asp:TextBox>
</td>
<td rowspan="4" style="border: thin solid #C0C0C0">
</td>
</tr>
<tr>
<td class="style2" colspan="2" style="border: thin solid #C0C0C0">
身份证号
</td>
<td class="style2" colspan="11" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtidcard" runat="server" Width="396px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2" colspan="2" style="border: thin solid #C0C0C0">
工作单位
</td>
<td class="style2" colspan="11" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtWork" runat="server" Width="500px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style9" colspan="2" style="border: thin solid #C0C0C0">
出生 地
</td>
<td class="style9" colspan="7" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtchushengdi" runat="server" Width="250px"></asp:TextBox>
</td>
<td class="style10" style="border: thin solid #C0C0C0">
民族</td>
<td class="style9" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtmingzu" runat="server" Height="24px" Width="101px"></asp:TextBox>
</td>
<td class="style11" style="border: thin solid #C0C0C0">
婚否</td>
<td class="style9" style="border: thin solid #C0C0C0">
<asp:CheckBox ID="hf" runat="server" />
</td>
</tr>
<tr>
<td class="style3" colspan="2" style="border: thin solid #C0C0C0">
既往病史</td>
<td class="style3" colspan="11" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtjwps" runat="server" Width="500px"></asp:TextBox>
</td>
<td style="border: thin solid #C0C0C0">
</td>
</tr>
<tr>
<td class="style3" colspan="2" style="border: thin solid #C0C0C0">
家族史</td>
<td class="style3" colspan="11" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtjzs" runat="server" Width="500px"></asp:TextBox>
</td>
<td style="border: thin solid #C0C0C0">
</td>
</tr>
<tr>
<td class="style12" rowspan="4" style="border: thin solid #C0C0C0">
眼</td>
<td colspan="4" style="border: thin solid #C0C0C0">
裸眼视力</td>
<td colspan="3" rowspan="3" style="border: thin solid #C0C0C0">
左</td>
<td class="style13" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtzlsl" runat="server" Width="250px"></asp:TextBox>
</td>
<td class="style15" rowspan="3" style="border: thin solid #C0C0C0">
右</td>
<td class="style6" colspan="3" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtylsl" runat="server" Width="250px"></asp:TextBox>
</td>
<td rowspan="4" style="border: thin solid #C0C0C0">
医师建议<br />
<br />
<br />
<br />
签名</td>
</tr>
<tr>
<td colspan="4" style="border: thin solid #C0C0C0">
矫正视力</td>
<td class="style13" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtzjzsl" runat="server" Width="250px"></asp:TextBox>
</td>
<td class="style6" colspan="3" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtyjsl" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="4" style="border: thin solid #C0C0C0">
眼疾</td>
<td class="style13" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtzyj" runat="server" Width="250px"></asp:TextBox>
</td>
<td class="style6" colspan="3" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtyyj" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="4" style="border: thin solid #C0C0C0">
色觉</td>
<td colspan="8" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtsj" runat="server" Width="600px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style12" rowspan="6" style="border: thin solid #C0C0C0">
耳鼻喉</td>
<td colspan="4" style="border: thin solid #C0C0C0">
听力</td>
<td colspan="3" rowspan="3" style="border: thin solid #C0C0C0">
左</td>
<td class="style13" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtztl" runat="server" Width="250px"></asp:TextBox>
</td>
<td class="style15" rowspan="3" style="border: thin solid #C0C0C0">
右</td>
<td colspan="3" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtytl" runat="server" Width="250px"></asp:TextBox>
</td>
<td rowspan="6" style="border: thin solid #C0C0C0">
医师建议
<br />
<br />
<br />
<br />
<br />
签名</td>
</tr>
<tr>
<td colspan="4" style="border: thin solid #C0C0C0">
耳疾</td>
<td class="style13" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtzej" runat="server" Width="250px"></asp:TextBox>
</td>
<td colspan="3" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtyej" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="4" style="border: thin solid #C0C0C0">
鼻及鼻窦</td>
<td class="style13" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtzbd" runat="server" Width="250px"></asp:TextBox>
</td>
<td colspan="3" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtybd" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3" style="border: thin solid #C0C0C0">
嗅觉</td>
<td colspan="9" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtxj" runat="server" Width="600px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3" style="border: thin solid #C0C0C0">
咽</td>
<td colspan="9" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtyan" runat="server" Width="500px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3" style="border: thin solid #C0C0C0">
喉</td>
<td colspan="9" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txthou" runat="server" Width="500px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style12" rowspan="3" style="border: thin solid #C0C0C0">
口腔</td>
<td colspan="3" style="border: thin solid #C0C0C0">
粘膜</td>
<td colspan="9" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtnm" runat="server" Width="500px"></asp:TextBox>
</td>
<td style="border: thin solid #C0C0C0">
</td>
</tr>
<tr>
<td colspan="3" style="border: thin solid #C0C0C0">
牙及牙龈</td>
<td colspan="9" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtyyin" runat="server" Width="500px"></asp:TextBox>
</td>
<td style="border: thin solid #C0C0C0">
</td>
</tr>
<tr>
<td colspan="3" style="border: thin solid #C0C0C0">
舌</td>
<td colspan="9" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtshe" runat="server" Width="500px"></asp:TextBox>
</td>
<td style="border: thin solid #C0C0C0">
</td>
</tr>
<tr>
<td class="style12" rowspan="8" style="border: thin solid #C0C0C0">
内科</td>
<td style="border: thin solid #C0C0C0">
呼吸</td>
<td style="border: thin solid #C0C0C0">
<asp:TextBox ID="txthx" runat="server" Height="23px" Width="50px"></asp:TextBox>
次/分</td>
<td colspan="3" style="border: thin solid #C0C0C0">
脉搏</td>
<td colspan="3" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtmb" runat="server" Height="23px" Width="50px"></asp:TextBox>
次/分</td>
<td class="style15" style="border: thin solid #C0C0C0">
血压</td>
<td colspan="3" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtxya" runat="server" Height="23px" Width="50px"></asp:TextBox>
/mHg</td>
<td rowspan="8" style="border: thin solid #C0C0C0">
医师建议<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
签名</td>
</tr>
<tr>
<td colspan="6" style="border: thin solid #C0C0C0">
发育及营养</td>
<td colspan="6" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtfy" runat="server" Width="500px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="6" style="border: thin solid #C0C0C0">
神经及精神</td>
<td colspan="6" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtsjjs" runat="server" Width="500px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="6" style="border: thin solid #C0C0C0">
肺及呼吸道</td>
<td colspan="6" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtfhx" runat="server" Width="500px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="6" style="border: thin solid #C0C0C0">
心脏及血管</td>
<td colspan="6" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtxxg" runat="server" Width="500px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="6" style="border: thin solid #C0C0C0">
肝、脾、双肾</td>
<td colspan="6" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtgps" runat="server" Width="500px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="6" style="border: thin solid #C0C0C0">
腹部包块</td>
<td colspan="6" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtfbaok" runat="server" Width="500px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="6" style="border: thin solid #C0C0C0">
其它</td>
<td colspan="6" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtqt" runat="server" Width="500px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style12" rowspan="6" style="border: thin solid #C0C0C0">
外科</td>
<td colspan="7" style="border: thin solid #C0C0C0">
身高</td>
<td style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtsg" runat="server" Width="200px"></asp:TextBox>
厘米</td>
<td class="style15" style="border: thin solid #C0C0C0">
体重</td>
<td class="style16" colspan="3" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txttz" runat="server" Height="21px" Width="138px"></asp:TextBox>
千克</td>
<td rowspan="6" style="border: thin solid #C0C0C0">
医师建议<br />
<br />
<br />
<br />
<br />
<br />
<br />
签名</td>
</tr>
<tr>
<td colspan="7" style="border: thin solid #C0C0C0">
皮肤</td>
<td style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtpf" runat="server" Width="200px"></asp:TextBox>
</td>
<td class="style15" style="border: thin solid #C0C0C0">
淋巴结</td>
<td colspan="3" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtlbj" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="7" style="border: thin solid #C0C0C0">
头、颈</td>
<td style="border: thin solid #C0C0C0">
<asp:TextBox ID="txttoujing" runat="server" Width="200px"></asp:TextBox>
</td>
<td class="style15" style="border: thin solid #C0C0C0">
甲状腺</td>
<td colspan="3" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtjzx" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="7" style="border: thin solid #C0C0C0">
脊柱</td>
<td style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtjz" runat="server" Width="200px"></asp:TextBox>
</td>
<td class="style15" style="border: thin solid #C0C0C0">
四肢</td>
<td colspan="3" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtsz" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="7" style="border: thin solid #C0C0C0">
肛门</td>
<td style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtgmen" runat="server" Width="200px"></asp:TextBox>
</td>
<td class="style15" style="border: thin solid #C0C0C0">
生殖器</td>
<td colspan="3" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtszq" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="7" style="border: thin solid #C0C0C0">
其它</td>
<td colspan="5" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtwqt" runat="server" Width="500px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style12" style="border: thin solid #C0C0C0">
辅助</td>
<td colspan="7" style="border: thin solid #C0C0C0">
胸片</td>
<td colspan="5" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtxp" runat="server" Width="500px"></asp:TextBox>
</td>
<td style="border: thin solid #C0C0C0">
医师签名: </td>
</tr>
<tr>
<td class="style12" rowspan="5" style="border: thin solid #C0C0C0">
检查结果</td>
<td colspan="7" style="border: thin solid #C0C0C0">
心电图</td>
<td colspan="5" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtxdt" runat="server" Width="500px"></asp:TextBox>
</td>
<td style="border: thin solid #C0C0C0">
医师签名: </td>
</tr>
<tr>
<td colspan="7" style="border: thin solid #C0C0C0">
肝功能</td>
<td colspan="5" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtggn" runat="server" Width="500px"></asp:TextBox>
</td>
<td style="border: thin solid #C0C0C0">
检验师签名: </td>
</tr>
<tr>
<td colspan="7" style="border: thin solid #C0C0C0">
乙肝两对半</td>
<td colspan="5" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtyglb" runat="server" Width="500px"></asp:TextBox>
</td>
<td style="border: thin solid #C0C0C0">
检验师签名: </td>
</tr>
<tr>
<td colspan="7" style="border: thin solid #C0C0C0">
血常规</td>
<td style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtxcg" runat="server"></asp:TextBox>
</td>
<td class="style15" style="border: thin solid #C0C0C0">
血型</td>
<td colspan="3" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtxx" runat="server"></asp:TextBox>
</td>
<td style="border: thin solid #C0C0C0">
检验师签名: </td>
</tr>
<tr>
<td colspan="7" style="border: thin solid #C0C0C0">
尿常规</td>
<td colspan="5" style="border: thin solid #C0C0C0">
<asp:TextBox ID="txtncg" runat="server" Width="500px"></asp:TextBox>
</td>
<td style="border: thin solid #C0C0C0">
检验师签名:</td>
</tr>
</table>
<div style=" margin-top:20px; height: 35px; text-align: center;">
<asp:Button ID="Button1" runat="server" οnclick="Button1_Click" Text="保存" />
</div>
</div>
</form>
</body>
</html>
后台CS:
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;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
string strcon = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request["id"]!=null)
{
DataTable dt = Method.SQLReturn("select * from my_yiyuan where id=@id",CommandType.Text,new SqlParameter("@id",Request["id"].ToString()));
if (dt.Rows.Count == 1)
{
txtname.Text=dt.Rows[0][1].ToString();
string sexa=dt.Rows[0][2].ToString();
sex.Checked = true;
if (sexa=="0")
{
sex0.Checked = true;
}
txtbrithday.Text=dt.Rows[0][3].ToString();
txtidcard.Text=dt.Rows[0][4].ToString();
string hf0=dt.Rows[0][5].ToString();
if (hf0=="1")
{
hf.Checked = true;
}
txtWork.Text=dt.Rows[0][6].ToString();
txtchushengdi.Text=dt.Rows[0][7].ToString();
txtmingzu.Text=dt.Rows[0][8].ToString();
txtjwps.Text=dt.Rows[0][9].ToString();
txtjzs.Text=dt.Rows[0][10].ToString();
txtzlsl.Text=dt.Rows[0][11].ToString();
txtzjzsl.Text=dt.Rows[0][12].ToString();
txtzyj.Text=dt.Rows[0][13].ToString();
txtylsl.Text=dt.Rows[0][14].ToString();
txtyjsl.Text=dt.Rows[0][15].ToString();
txtyyj.Text=dt.Rows[0][16].ToString();
txtsj.Text=dt.Rows[0][17].ToString();
txtztl.Text=dt.Rows[0][18].ToString();
txtzej.Text=dt.Rows[0][19].ToString();
txtzbd.Text=dt.Rows[0][20].ToString();
txtytl.Text=dt.Rows[0][21].ToString();
txtyej.Text=dt.Rows[0][22].ToString();
txtybd.Text=dt.Rows[0][23].ToString();
txtxj.Text=dt.Rows[0][24].ToString();
txtyan.Text=dt.Rows[0][25].ToString();
txthou.Text=dt.Rows[0][26].ToString();
txtnm.Text=dt.Rows[0][27].ToString();
txtyyin.Text=dt.Rows[0][28].ToString();
txtshe.Text=dt.Rows[0][29].ToString();
txthx.Text=dt.Rows[0][30].ToString();
txtmb.Text=dt.Rows[0][31].ToString();
txtxya.Text=dt.Rows[0][32].ToString();
txtfy.Text=dt.Rows[0][33].ToString();
txtsjjs.Text=dt.Rows[0][34].ToString();
txtfhx.Text=dt.Rows[0][35].ToString();
txtxxg.Text=dt.Rows[0][36].ToString();
txtgps.Text=dt.Rows[0][37].ToString();
txtfbaok.Text=dt.Rows[0][38].ToString();
txtqt.Text=dt.Rows[0][39].ToString();
txtsg.Text=dt.Rows[0][40].ToString();
txttz.Text=dt.Rows[0][41].ToString();
txtpf.Text=dt.Rows[0][42].ToString();
txtlbj.Text=dt.Rows[0][43].ToString();
txttoujing.Text=dt.Rows[0][44].ToString();
txtjzx.Text=dt.Rows[0][45].ToString();
txtjz.Text=dt.Rows[0][46].ToString();
txtsz.Text=dt.Rows[0][47].ToString();
txtgmen.Text=dt.Rows[0][48].ToString();
txtszq.Text=dt.Rows[0][49].ToString();
txtwqt.Text=dt.Rows[0][50].ToString();
txtxp.Text=dt.Rows[0][51].ToString();
txtxdt.Text=dt.Rows[0][52].ToString();
txtggn.Text=dt.Rows[0][53].ToString();
txtyglb.Text=dt.Rows[0][54].ToString();
txtxcg.Text=dt.Rows[0][55].ToString();
txtxx.Text=dt.Rows[0][56].ToString();
txtncg.Text = dt.Rows[0][57].ToString();
if (Request["sign"] != null)
{
Button1.Text = "修改";
}
else
{
Button1.Text = "返回";
tabledisp.Disabled = true;
}
}
else
{
ClientScript.RegisterClientScriptBlock(GetType(),"aa","<script>alert('数据出现问题请联系管理员')</script>");
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
if (btn.Text == "保存")
{
WriteDataBase();
}
else if (btn.Text == "修改")
{
updateDataBase();
Server.Transfer("Disp.aspx");
}
else
{
Server.Transfer("Disp.aspx");
}
}
private void WriteDataBase()
{
string sexa = "0";
if (sex.Checked)
{
sexa = "1";
}
string hf0 = "0";
if (hf.Checked)
{
hf0 = "1";
}
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into my_yiyuan(");
strSql.Append("name,sex,brithday,idcard,ishf,workdw,chushengdi,mingzu,jiwangbingshi,jiazushi,zls,zjx,zjj,yls,yjx,yjj,sejue,ztl,zej,zbd,ytl,yej,ybd,xj,y,h,nm,yyin,she,huxi,maibo,xueya,fayue,shenjing,feihuxidao,xinzangxueguan,ganpishen,fubobaokuai,neiqita,shengao,tizhong,pifu,libajie,toujing,jiazhuangxian,jizhu,sizhi,gangmen,shengzhiqi,waiqita,xiongpian,xindiantu,gangongneng,yiganliandiuban,xuechanggui,xuexing,niaochanggui)");
strSql.Append(" values (");
strSql.Append("@name,@sex,@brithday,@idcard,@ishf,@workdw,@chushengdi,@mingzu,@jiwangbingshi,@jiazushi,@zls,@zjx,@zjj,@yls,@yjx,@yjj,@sejue,@ztl,@zej,@zbd,@ytl,@yej,@ybd,@xj,@y,@h,@nm,@yyin,@she,@huxi,@maibo,@xueya,@fayue,@shenjing,@feihuxidao,@xinzangxueguan,@ganpishen,@fubobaokuai,@neiqita,@shengao,@tizhong,@pifu,@libajie,@toujing,@jiazhuangxian,@jizhu,@sizhi,@gangmen,@shengzhiqi,@waiqita,@xiongpian,@xindiantu,@gangongneng,@yiganliandiuban,@xuechanggui,@xuexing,@niaochanggui)");
SqlParameter[] parameters = {
new SqlParameter("@name", txtname.Text.Trim()),
new SqlParameter("@sex",sexa),
new SqlParameter("@brithday", txtbrithday.Text.Trim()),
new SqlParameter("@idcard",txtidcard.Text.Trim()),
new SqlParameter("@ishf",hf0),
new SqlParameter("@workdw", txtWork.Text.Trim()),
new SqlParameter("@chushengdi",txtchushengdi.Text.Trim()),
new SqlParameter("@mingzu",txtmingzu.Text.Trim()),
new SqlParameter("@jiwangbingshi",txtjwps.Text.Trim()),
new SqlParameter("@jiazushi",txtjzs.Text.Trim()),
new SqlParameter("@zls", txtzlsl.Text.Trim()),
new SqlParameter("@zjx",txtzjzsl.Text.Trim()),
new SqlParameter("@zjj",txtzyj.Text.Trim()),
new SqlParameter("@yls",txtylsl.Text.Trim()),
new SqlParameter("@yjx", txtyjsl.Text.Trim()),
new SqlParameter("@yjj", txtyyj.Text.Trim()),
new SqlParameter("@sejue", txtsj.Text.Trim()),
new SqlParameter("@ztl", txtztl.Text.Trim()),
new SqlParameter("@zej", txtzej.Text.Trim()),
new SqlParameter("@zbd",txtzbd.Text.Trim()),
new SqlParameter("@ytl", txtytl.Text.Trim()),
new SqlParameter("@yej", txtyej.Text.Trim()),
new SqlParameter("@ybd", txtybd.Text.Trim()),
new SqlParameter("@xj", txtxj.Text.Trim()),
new SqlParameter("@y", txtyan.Text.Trim()),
new SqlParameter("@h", txthou.Text.Trim()),
new SqlParameter("@nm", txtnm.Text.Trim()),
new SqlParameter("@yyin", txtyyin.Text.Trim()),
new SqlParameter("@she", txtshe.Text.Trim()),
new SqlParameter("@huxi", txthx.Text.Trim()),
new SqlParameter("@maibo", txtmb.Text.Trim()),
new SqlParameter("@xueya", txtxya.Text.Trim()),
new SqlParameter("@fayue", txtfy.Text.Trim()),
new SqlParameter("@shenjing", txtsjjs.Text.Trim()),
new SqlParameter("@feihuxidao",txtfhx.Text.Trim()),
new SqlParameter("@xinzangxueguan", txtxxg.Text.Trim()),
new SqlParameter("@ganpishen", txtgps.Text.Trim()),
new SqlParameter("@fubobaokuai", txtfbaok.Text.Trim()),
new SqlParameter("@neiqita", txtqt.Text.Trim()),
new SqlParameter("@shengao", txtsg.Text.Trim()),
new SqlParameter("@tizhong",txttz.Text.Trim()),
new SqlParameter("@pifu", txtpf.Text.Trim()),
new SqlParameter("@libajie", txtlbj.Text.Trim()),
new SqlParameter("@toujing", txttoujing.Text.Trim()),
new SqlParameter("@jiazhuangxian", txtjzx.Text.Trim()),
new SqlParameter("@jizhu", txtjz.Text.Trim()),
new SqlParameter("@sizhi", txtsz.Text.Trim()),
new SqlParameter("@gangmen", txtgmen.Text.Trim()),
new SqlParameter("@shengzhiqi", txtszq.Text.Trim()),
new SqlParameter("@waiqita", txtwqt.Text.Trim()),
new SqlParameter("@xiongpian", txtxp.Text.Trim()),
new SqlParameter("@xindiantu", txtxdt.Text.Trim()),
new SqlParameter("@gangongneng", txtggn.Text.Trim()),
new SqlParameter("@yiganliandiuban", txtyglb.Text.Trim()),
new SqlParameter("@xuechanggui", txtxcg.Text.Trim()),
new SqlParameter("@xuexing", txtxx.Text.Trim()),
new SqlParameter("@niaochanggui", txtncg.Text.Trim())};
Method.SQLExecute(strSql.ToString(), CommandType.Text, parameters);
ClientScript.RegisterClientScriptBlock(GetType(), "aaa", "<script>alert('写入成功!')</script>");
}
private void updateDataBase()
{
string sexa = "0";
if (sex.Checked)
{
sexa = "1";
}
string hf0 = "0";
if (hf.Checked)
{
hf0 = "1";
}
StringBuilder strSql=new StringBuilder();
strSql.Append("update my_yiyuan set ");
strSql.Append("name=@name,");
strSql.Append("sex=@sex,");
strSql.Append("brithday=@brithday,");
strSql.Append("idcard=@idcard,");
strSql.Append("ishf=@ishf,");
strSql.Append("workdw=@workdw,");
strSql.Append("chushengdi=@chushengdi,");
strSql.Append("mingzu=@mingzu,");
strSql.Append("jiwangbingshi=@jiwangbingshi,");
strSql.Append("jiazushi=@jiazushi,");
strSql.Append("zls=@zls,");
strSql.Append("zjx=@zjx,");
strSql.Append("zjj=@zjj,");
strSql.Append("yls=@yls,");
strSql.Append("yjx=@yjx,");
strSql.Append("yjj=@yjj,");
strSql.Append("sejue=@sejue,");
strSql.Append("ztl=@ztl,");
strSql.Append("zej=@zej,");
strSql.Append("zbd=@zbd,");
strSql.Append("ytl=@ytl,");
strSql.Append("yej=@yej,");
strSql.Append("ybd=@ybd,");
strSql.Append("xj=@xj,");
strSql.Append("y=@y,");
strSql.Append("h=@h,");
strSql.Append("nm=@nm,");
strSql.Append("yyin=@yyin,");
strSql.Append("she=@she,");
strSql.Append("huxi=@huxi,");
strSql.Append("maibo=@maibo,");
strSql.Append("xueya=@xueya,");
strSql.Append("fayue=@fayue,");
strSql.Append("shenjing=@shenjing,");
strSql.Append("feihuxidao=@feihuxidao,");
strSql.Append("xinzangxueguan=@xinzangxueguan,");
strSql.Append("ganpishen=@ganpishen,");
strSql.Append("fubobaokuai=@fubobaokuai,");
strSql.Append("neiqita=@neiqita,");
strSql.Append("shengao=@shengao,");
strSql.Append("tizhong=@tizhong,");
strSql.Append("pifu=@pifu,");
strSql.Append("libajie=@libajie,");
strSql.Append("toujing=@toujing,");
strSql.Append("jiazhuangxian=@jiazhuangxian,");
strSql.Append("jizhu=@jizhu,");
strSql.Append("sizhi=@sizhi,");
strSql.Append("gangmen=@gangmen,");
strSql.Append("shengzhiqi=@shengzhiqi,");
strSql.Append("waiqita=@waiqita,");
strSql.Append("xiongpian=@xiongpian,");
strSql.Append("xindiantu=@xindiantu,");
strSql.Append("gangongneng=@gangongneng,");
strSql.Append("yiganliandiuban=@yiganliandiuban,");
strSql.Append("xuechanggui=@xuechanggui,");
strSql.Append("xuexing=@xuexing,");
strSql.Append("niaochanggui=@niaochanggui");
strSql.Append(" where id=@id ");
SqlParameter[] parameters = {
new SqlParameter("@name", txtname.Text.Trim()),
new SqlParameter("@sex",sexa),
new SqlParameter("@brithday", txtbrithday.Text.Trim()),
new SqlParameter("@idcard",txtidcard.Text.Trim()),
new SqlParameter("@ishf",hf0),
new SqlParameter("@workdw", txtWork.Text.Trim()),
new SqlParameter("@chushengdi",txtchushengdi.Text.Trim()),
new SqlParameter("@mingzu",txtmingzu.Text.Trim()),
new SqlParameter("@jiwangbingshi",txtjwps.Text.Trim()),
new SqlParameter("@jiazushi",txtjzs.Text.Trim()),
new SqlParameter("@zls", txtzlsl.Text.Trim()),
new SqlParameter("@zjx",txtzjzsl.Text.Trim()),
new SqlParameter("@zjj",txtzyj.Text.Trim()),
new SqlParameter("@yls",txtylsl.Text.Trim()),
new SqlParameter("@yjx", txtyjsl.Text.Trim()),
new SqlParameter("@yjj", txtyyj.Text.Trim()),
new SqlParameter("@sejue", txtsj.Text.Trim()),
new SqlParameter("@ztl", txtztl.Text.Trim()),
new SqlParameter("@zej", txtzej.Text.Trim()),
new SqlParameter("@zbd",txtzbd.Text.Trim()),
new SqlParameter("@ytl", txtytl.Text.Trim()),
new SqlParameter("@yej", txtyej.Text.Trim()),
new SqlParameter("@ybd", txtybd.Text.Trim()),
new SqlParameter("@xj", txtxj.Text.Trim()),
new SqlParameter("@y", txtyan.Text.Trim()),
new SqlParameter("@h", txthou.Text.Trim()),
new SqlParameter("@nm", txtnm.Text.Trim()),
new SqlParameter("@yyin", txtyyin.Text.Trim()),
new SqlParameter("@she", txtshe.Text.Trim()),
new SqlParameter("@huxi", txthx.Text.Trim()),
new SqlParameter("@maibo", txtmb.Text.Trim()),
new SqlParameter("@xueya", txtxya.Text.Trim()),
new SqlParameter("@fayue", txtfy.Text.Trim()),
new SqlParameter("@shenjing", txtsjjs.Text.Trim()),
new SqlParameter("@feihuxidao",txtfhx.Text.Trim()),
new SqlParameter("@xinzangxueguan", txtxxg.Text.Trim()),
new SqlParameter("@ganpishen", txtgps.Text.Trim()),
new SqlParameter("@fubobaokuai", txtfbaok.Text.Trim()),
new SqlParameter("@neiqita", txtqt.Text.Trim()),
new SqlParameter("@shengao", txtsg.Text.Trim()),
new SqlParameter("@tizhong",txttz.Text.Trim()),
new SqlParameter("@pifu", txtpf.Text.Trim()),
new SqlParameter("@libajie", txtlbj.Text.Trim()),
new SqlParameter("@toujing", txttoujing.Text.Trim()),
new SqlParameter("@jiazhuangxian", txtjzx.Text.Trim()),
new SqlParameter("@jizhu", txtjz.Text.Trim()),
new SqlParameter("@sizhi", txtsz.Text.Trim()),
new SqlParameter("@gangmen", txtgmen.Text.Trim()),
new SqlParameter("@shengzhiqi", txtszq.Text.Trim()),
new SqlParameter("@waiqita", txtwqt.Text.Trim()),
new SqlParameter("@xiongpian", txtxp.Text.Trim()),
new SqlParameter("@xindiantu", txtxdt.Text.Trim()),
new SqlParameter("@gangongneng", txtggn.Text.Trim()),
new SqlParameter("@yiganliandiuban", txtyglb.Text.Trim()),
new SqlParameter("@xuechanggui", txtxcg.Text.Trim()),
new SqlParameter("@xuexing", txtxx.Text.Trim()),
new SqlParameter("@niaochanggui", txtncg.Text.Trim()),
new SqlParameter("@id", Request["id"].ToString())
};
Method.SQLExecute(strSql.ToString(), CommandType.Text, parameters);
ClientScript.RegisterClientScriptBlock(GetType(), "aaa", "<script>alert('修改成功!')</script>");
}
}
前台html:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Disp.aspx.cs" Inherits="Disp" %>
<!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>
<style type="text/css">
.style1
{
font-size: small;
}
</style>
<script src="Scripts/jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#Checkbox1").click(function () {
$("#GridView1 tr input[id!=Checkbox1]").attr("checked",this.checked);
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="删除选中项" οnclick="Button1_Click" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" οnclick="Button2_Click" Text="查找" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="748px" style="text-align: center"
onrowcommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<input id="Checkbox1" type="checkbox" />
</HeaderTemplate>
</asp:TemplateField>
<asp:HyperLinkField HeaderText="姓名" DataNavigateUrlFields="id"
DataNavigateUrlFormatString="Default.aspx?id={0}" DataTextField="name" />
<asp:TemplateField HeaderText="性别">
<ItemTemplate>
<%# Convert.ToBoolean(Eval("sex"))?"男":"女" %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="mingzu" HeaderText="民族" />
<asp:TemplateField HeaderText="婚否">
<ItemTemplate>
<%# Convert.ToBoolean(Eval("ishf"))?"已婚":"未婚" %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="brithday" HeaderText="出生日期" />
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("id") %>'
CssClass="style1" CommandName="ed">[修改]</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server"
CommandArgument='<%# Eval("id") %>' CssClass="style1" CommandName="del">[删除]</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
后台CS:
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;
public partial class Disp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["sql"] = "select * from my_yiyuan";
DataBindGrid();
}
}
protected void DataBindGrid()
{
DataTable dt = Method.SQLReturn(ViewState["sql"].ToString(),CommandType.Text);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
int i=0;
foreach (GridViewRow item in GridView1.Rows)
{
CheckBox cb = item.Cells[0].FindControl("CheckBox2") as CheckBox;
if (cb == null)
{
return;
}
LinkButton link = item.Cells[6].FindControl("LinkButton1") as LinkButton;
if (link == null)
{
return;
}
if (cb.Checked)
{
Method.SQLExecute("delete from my_yiyuan where id=@id", CommandType.Text, new SqlParameter("@id", link.CommandArgument.ToString()));
i++;
}
}
ClientScript.RegisterClientScriptBlock(GetType(),"aa","<script>alert('已经成功删除了"+i.ToString()+"条记录')</script>");
DataBindGrid();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName=="ed")
{
Server.Transfer("Default.aspx?id="+e.CommandArgument+"&sign=0");
}
else if (e.CommandName == "del")
{
Method.SQLExecute("delete from my_yiyuan where id=@id",CommandType.Text,new SqlParameter("@id",e.CommandArgument));
}
DataBindGrid();
}
protected void Button2_Click(object sender, EventArgs e)
{
ViewState["sql"] = "select * from my_yiyuan where name like '%"+TextBox1.Text.Trim()+"%'";
DataBindGrid();
}
}