留言本(7)管理员管理留言本

本文介绍了使用ASP.NET中的GridView控件实现数据展示的方法,包括数据绑定、行高亮及添加新管理员等功能,并探讨了在操作过程中遇到的问题。

 

主要用的是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 = "";
    }
}

这个留言本到此就结束了,希望路过的朋友指点,本留言本有一个缺点就是回复某留言的留言显示在某留言上,因为是按时间排序显示留言,我刚开始没注意,所以就没写,知道的朋友请给我留言,留下宝贵的意见!我很希望遇上某个朋友的指点,毕竟我一个人学,有很多想不通的问题。谢谢!

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值