📄 leaveword.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
DB db = new DB();
string curPage;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.lblPageCur.Text = "1";
dataGridBind();
page();
for (int i = 1; i <= 10; i++)
{
this.ddlPic.Items.Add("pic" + i.ToString() + ".gif");
}
this.Image1.ImageUrl = "images/face/" + ddlPic.SelectedValue;
}
}
public void dataGridBind()
{
curPage = this.lblPageCur.Text.ToString();
SqlConnection con = db.getcon();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from leaveWord";
cmd.Connection = con;
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds, "leaveWord");
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = 3;
pds.DataSource = ds.Tables["leaveWord"].DefaultView;
pds.CurrentPageIndex = Convert.ToInt32(curPage)-1;
this.lblPageTotal.Text = pds.PageCount.ToString();
this.Button3.Enabled = true;
this.Button4.Enabled = true;
if (curPage == "1")
{
this.Button3.Enabled = false;
}
if (curPage == pds.PageCount.ToString())
{
this.Button4.Enabled = false;
}
this.DataList1.DataSource = pds;
this.DataList1.DataBind();
cmd.CommandText = "select count(*) from leaveWord";
this.lblMesTotal.Text = Convert.ToString(cmd.ExecuteScalar());
}
public void page()
{
SqlConnection con = db.getcon();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from leaveWord";
cmd.Connection = con;
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds, "leaveWord");
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = 3;
pds.DataSource = ds.Tables["leaveWord"].DefaultView;
pds.CurrentPageIndex = Convert.ToInt32(curPage) - 1;
int a = pds.PageCount;
for (int i = 1; i <= a; i++)
{
this.DropDownList1.Items.Add(i.ToString());
}
}
/*protected void ddlPic_SelectedIndexChanged(object sender, EventArgs e)
{
this.Image1.ImageUrl = "~/images/face/" + ddlPic.SelectedValue;
}
*/
protected void Button3_Click(object sender, EventArgs e)
{
this.lblPageCur.Text = Convert.ToString(Convert.ToInt32(this.lblPageCur.Text) - 1);
dataGridBind();
}
protected void Button4_Click(object sender, EventArgs e)
{
this.lblPageCur.Text = Convert.ToString(Convert.ToInt32(this.lblPageCur.Text) + 1);
dataGridBind();
}
protected void Button5_Click(object sender, EventArgs e)
{
this.lblPageCur.Text = "1";
dataGridBind();
}
protected void Button6_Click(object sender, EventArgs e)
{
this.lblPageCur.Text = this.lblPageTotal.Text;
dataGridBind();
}
protected void Button7_Click(object sender, EventArgs e)
{
this.lblPageCur.Text = this.DropDownList1.SelectedValue;
dataGridBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
string sex;
//string postTime; //时间为数据库更新时自动根据系统时间设置
//string imageUrl;
string userName = this.txtUserName.Text;
string url = this.txtUrl.Text;
string qq = this.txtQq.Text;
string email = this.txtEmail.Text;
string content = this.txtContent.Text;
string imageUrl = ddlPic.SelectedValue;
if (this.rbtnNv.Checked == true)
{
sex = "女";
}
else
{
sex = "男";
}
SqlConnection conn =db.getcon();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "insert into leaveWord(姓名,sex,url,qq,emali,内容,image,时间) values('"+userName+"','"+sex+"','"+url+"','"+qq+"','"+email+"','"+content+"','"+imageUrl+"','"+Convert.ToDateTime(DateTime.Today)+"')";
if (cmd.ExecuteNonQuery() > 0)
{
this.Label2.Text="留言成功!";
//this.DataList1.DataBind();
}
else
{
this.Label2.Text="留言成功!";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
this.txtUserName.Text = "";
this.txtUrl.Text = "";
this.txtQq.Text = "";
this.txtEmail.Text = "";
this.txtContent.Text = "";
}
protected void lbtnReply_Command(object sender, CommandEventArgs e)
{
string id = e.CommandArgument.ToString();
Response.Redirect("reply.aspx?id=" + id);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -