留言本(7)管理员管理留言本
来源:互联网 发布:python安装pip win10 编辑:程序博客网 时间:2024/05/16 06:41
主要用的是GridVIew控件。直接新建数据源用的是book的两个表。还有就是移动到数据行实现变色功能和添加新和管理员。主要都是手工做的,没写什么代码!
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 admin : System.Web.UI.Page
{
public DataSet ds;
int id;
protected void Page_Load(object sender, EventArgs e)
{
id = DB.ExecuteScalar("select max(id) from admin");
id = id + 1;
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#ffff00';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
}
}
protected void GridView2_RowCreated(object sender, GridViewRowEventArgs e)//实现变色
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#ffff00';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
}
}
protected void Button1_Click1(object sender, EventArgs e)//添加到数据表
{
DB.ExecuteNonQuery("insert into admin values("+id+",'"+TextBox2 .Text +"','"+TextBox3 .Text +"')");
GridView2.DataBind();//马上实现能在GridView控件上显示刚刚加的用户,在这儿,我有问题求救,为什么我要点击两次才能在gridview上显示刚添加的用户,请知道的朋友指点,本人非常感谢!
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
}
这个留言本到此就结束了,希望路过的朋友指点,本留言本有一个缺点就是回复某留言的留言显示在某留言上,因为是按时间排序显示留言,我刚开始没注意,所以就没写,知道的朋友请给我留言,留下宝贵的意见!我很希望遇上某个朋友的指点,毕竟我一个人学,有很多想不通的问题。谢谢!