62,046
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserEditOrAdd.aspx.cs"
Inherits="CreditCardManage.User.UserEditOrAdd" %>
<!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: 600px;
height: 400px;
}
.style2
{
width: 100%;
}
.style3
{
height: 100px;
}
.style4
{
height: 34px;
}
.style5
{
height: 30px;
}
.style6
{
height: 82px;
}
</style>
</head>
<body>
<form id="form1" runat="server" enableviewstate="True">
<div>
<table border="1" cellpadding="0" cellspacing="0" frame="box">
<tr>
<td>
<table class="style2" rules="all" frame="void" cellpadding="1" cellspacing="0">
<tr>
<td colspan="4">
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="返回列表" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server"></asp:Label>
</td>
</tr>
<tr class="style5">
<td>
用户姓名
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" BorderColor="Black" BorderStyle="Solid"
BorderWidth="1px" Height="30px"></asp:TextBox>
</td>
<td>
身份证号
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" BorderColor="Black" BorderStyle="Solid"
BorderWidth="1px" Height="30px"></asp:TextBox>
</td>
</tr>
<tr class="style5">
<td class="style6">
性别
</td>
<td class="style6" valign="top">
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Selected="True">男</asp:ListItem>
<asp:ListItem>女</asp:ListItem>
</asp:RadioButtonList>
</td>
<td class="style6">
个人信用等级
</td>
<td class="style6" valign="top">
<asp:DropDownList ID="DropDownList1" runat="server" Height="35px" Width="144px">
<asp:ListItem Selected="True">低级</asp:ListItem>
<asp:ListItem>中级</asp:ListItem>
<asp:ListItem>高级</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style5">
卡内金额
</td>
<td class="style5">
<asp:TextBox ID="TextBox3" runat="server" BorderColor="Black" BorderStyle="Solid"
BorderWidth="1px" Height="30px"></asp:TextBox>
</td>
<td class="style5">
联系电话
</td>
<td class="style5">
<asp:TextBox ID="TextBox4" runat="server" BorderColor="Black" BorderStyle="Solid"
BorderWidth="1px" Height="30px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style4">
家庭住址
</td>
<td class="style4" colspan="3">
<asp:TextBox ID="TextBox5" runat="server" Width="394px" BorderColor="Black" BorderStyle="Solid"
BorderWidth="1px" Height="30px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
其他说明
</td>
<td class="style3" colspan="3">
<asp:TextBox ID="TextBox6" runat="server" Height="90px" TextMode="MultiLine" Width="394px"
BorderColor="#000001" BorderStyle="Solid" BorderWidth="1px"></asp:TextBox>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
namespace CreditCardManage.User
{
public partial class UserEditOrAdd : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
try
{
//有id时是修改模块
string id = Request["id"].ToString();
Button1.Text = "保存修改";
try
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from CardUserInfo where CreditCardGuid=@CreditCardGuid", con);
cmd.Parameters.AddWithValue(@"CreditCardGuid", id);
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
TextBox1.Text = sdr["UserName"].ToString();
TextBox2.Text = sdr["IdentityCardNumber"].ToString();
TextBox3.Text = sdr["Money"].ToString();
TextBox4.Text = sdr["PhoneNumber"].ToString();
if (sdr["Sex"].ToString().Trim() == "男")
{
RadioButtonList1.SelectedIndex = 0;
}
else
{
RadioButtonList1.SelectedIndex = 1;
}
if (sdr["CreditStandard"].ToString().Trim() == "低级")
{
DropDownList1.SelectedIndex = 0;
}
else if (sdr["CreditStandard"].ToString().Trim() == "中级")
{
DropDownList1.SelectedIndex = 1;
}
else
{
DropDownList1.SelectedIndex = 2;
}
sdr.Close();
}
catch (Exception)
{
throw;
}
finally
{
con.Close();
}
}
catch (Exception)
{
//如果没有找到id,页面是添加模块
Button1.Text = "新增";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "";
//判断是添加用户还是编辑用户
if (Button1.Text == "新增")
{
/*****........*****/
}
else /**************就是这里**************/
{
string ss = TextBox4.Text.Trim()
con.Open();
SqlCommand cmd = new SqlCommand("update CardUserInfo set UserName=@UserName,IdentityCardNumber=@IdentityCardNumber,"
+ "Sex=@Sex,CreditStandard=@CreditStandard,Money=@Money,PhoneNumber=@PhoneNumber,"
+ "HomeAddress=@HomeAddress,Note=@Note where CreditCardGuid=@CreditCardGuid", con);
cmd.Parameters.AddWithValue("@UserName", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@IdentityCardNumber", TextBox2.Text.Trim());
cmd.Parameters.AddWithValue("@Sex", RadioButtonList1.SelectedValue);
cmd.Parameters.AddWithValue("@CreditStandard", DropDownList1.SelectedValue);
cmd.Parameters.AddWithValue("@Money", Convert.ToDecimal(TextBox3.Text.Trim()));
cmd.Parameters.AddWithValue("@PhoneNumber", TextBox4.Text.Trim());
cmd.Parameters.AddWithValue("@HomeAddress", TextBox5.Text.Trim());
cmd.Parameters.AddWithValue("@Note", TextBox6.Text);
cmd.Parameters.AddWithValue("@CreditCardGuid", Request["id"].ToString());
if ((int)cmd.ExecuteNonQuery() > 0)
{
Label1.Text = "更新成功!";
}
if (!IsPostBack)
{
Bind();
}
private void Page_Load()
{
if (!IsPostBack)
{
// Validate initially to force asterisks
// to appear before the first roundtrip.
Validate();
}
}
以上来自msdn:
https://msdn.microsoft.com/en-us/library/system.web.ui.page.ispostback(v=vs.110).aspx