62,046
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace Classmates
{
public partial class joinClass : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindToGridView();
string name = string.Empty;
if (Session["name"] == null)
{
name = "登录";
}
else
{
name = Session["name"].ToString();
}
if (name == "登录")
{
LinkButton3.Visible = false;
LinkButton1.Text = name;
//HyperLink1.NavigateUrl = "UserLogin.aspx";
LinkButton2.Text = "立即注册";
//HyperLink2.NavigateUrl = "UserRegister.aspx";
}
else
{
LinkButton1.Text = name;
LinkButton2.Text = "退出";
LinkButton3.Visible = true;
LinkButton3.Text = "未找到班级?立即创建";
// HyperLink2.NavigateUrl = "joinClass.aspx";
/*Session["name"] = null;
HyperLink1.Text = "登录";
HyperLink1.NavigateUrl = "UserLogin.aspx";
HyperLink2.Text = "立即注册";
HyperLink2.NavigateUrl = "UserRegister.aspx"; */
;
}
}
}
private void BindToGridView()
{
string connectionstring = ConfigurationManager.ConnectionStrings["conn"].ToString();
SqlConnection conn2 = new SqlConnection(connectionstring);
conn2.Open();
string sqlString = "select * from class order by cno asc ";
SqlDataAdapter sda = new SqlDataAdapter(sqlString, conn2);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
conn2.Close();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
//登录时的单击操作
if (LinkButton1.Text == "登录")
{
Response.Redirect("http://localhost:9665/UserLogin.aspx");
}
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
if (LinkButton2.Text == "立即注册")
{
Response.Redirect("http://localhost:9665/UserRegister.aspx");
}
if (LinkButton2.Text == "退出")
{
Session["name"] = null;
Response.Redirect("http://localhost:9665/joinClass.aspx");
LinkButton1.Text = "登录";
LinkButton2.Text = "立即注册";
}
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
if (Session["name"] !=null)
{
Response.Redirect("http://localhost:9665/createClass.aspx");
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Redirect("http://localhost:9665/RegisterInClass.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
string date = DropDownList1.SelectedValue;
string kd = TextBox1.Text.Trim();
string connectionstring = ConfigurationManager.ConnectionStrings["conn"].ToString();
SqlConnection conn2 = new SqlConnection(connectionstring);
conn2.Open();
string sqlString = "select * from class where cdate = '" + date + "' or cname like '%" + kd + "%' order by cno asc ";
SqlDataAdapter sda = new SqlDataAdapter(sqlString, conn2);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
conn2.Close();
}
}
}