前台代码
<%@ Page Title="" Language="C#" MasterPageFile="~/Teacher.Master" AutoEventWireup="true" CodeBehind="teacher2.aspx.cs" Inherits="周五重点.teacher2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div>
<p>姓名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></p>
<p>密码:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></p>
<p>电话:<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></p>
<p>住址:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></p>
<p>生日:<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label></p>
<p>爱好:</p>
<p>
<asp:Panel ID="Panel1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" Text="唱歌" />
<asp:CheckBox ID="CheckBox2" runat="server" Text="跳舞" />
<asp:CheckBox ID="CheckBox3" runat="server" Text="学习" />
<asp:CheckBox ID="CheckBox4" runat="server" Text="羽毛球"/>
<asp:CheckBox ID="CheckBox5" runat="server" Text="篮球" />
</asp:Panel>
</p>
</div>
</asp:Content>
后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace 周五重点
{
public partial class teacher2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uid"]!=null)
{
int id = int.Parse(Session["uid"].ToString());
DataTable dt = BLL.Manager.userGetId(id);
this.TextBox1.Text = dt.Rows[0]["UserName"].ToString();
this.TextBox2.Text = dt.Rows[0]["UserPwd"].ToString();
this.TextBox3.Text = dt.Rows[0]["UserTel"].ToString();
this.Label1.Text = dt.Rows[0]["UserAddr"].ToString();
this.Label2.Text = ((DateTime)dt.Rows[0]["UserBirth"]).ToLongDateString();
var hobby = dt.Rows[0]["UserHobby"].ToString().Split(',');
foreach (var item in hobby)
{
foreach (Control cl in Panel1.Controls)
{
if (cl is CheckBox)
{
CheckBox ck=(CheckBox)cl;
if (item==ck.Text)
{
ck.Checked = true;
}
}
}
}
}
}
}
}