新手测试题目的Default.aspx与Default.cs的内容。

Default.aspx内容:

 

 

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>网站维护列表</title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<link href="style.css" rel="stylesheet" type="text/css" />
<style>
#showspace {height:20px; padding-left:10px; line-height:20px; cursor:pointer;}
#showspace :hover{ background:#8fc400;}
#showspace  label{float:left; display:inline; font-weight:bold;}
</style>
</head>
<body>

<form id="form1" runat="server">
    <div>
        <table border="0" cellpadding="0" cellspacing="0"
            style="width: 760px; position: relative; top: 0px; left: 0px;">
            <tr>
                <td>
                    <asp:DataList ID="DataList1" runat="server"
                        Style="position: relative; top: 0px; left: 0px;"
                        OnItemDataBound="DataList1_ItemDataBound" Width="100%">
                        <ItemTemplate>
                            <table border="0" cellpadding="0" cellspacing="0" style="left: 1px; width: 996px;
                                position: relative; top: 0px; border-right: #e8e8e8 1px solid; border-left: #e8e8e8 1px solid; height: 100%;" id="showspace" οnmοuseοver="airport(this)" οnmοuseοut="airporthover(this)">
                                <tr >
                                    <td  style="width: 200px; border-right: #e8e8e8 1px solid;" align="center" >
                                       
                                        <asp:Label ID="lblUser" runat="server" Style="position: relative" Text=<%#DataBinder.Eval(Container.DataItem,"ID") %>  ></asp:Label></td>
                                     <td style="width: 200px; border-right: #e8e8e8 1px solid;" align="center">
                                       
                                        <asp:Label ID="Label1" runat="server" Style="position: relative" Text=<%#DataBinder.Eval(Container.DataItem,"ProjName") %>></asp:Label></td>
                                        <td style="width: 200px; border-right: #e8e8e8 1px solid;" align="center">
                                       
                                        <asp:Label ID="Label2" runat="server" Style="position: relative" Text=<%#DataBinder.Eval(Container.DataItem,"Customer") %>></asp:Label></td>
                                        <td style="width: 200px; border-right: #e8e8e8 1px solid;" align="center">
                                       
                                        <asp:Label ID="Label3" runat="server" Style="position: relative" Text=<%#DataBinder.Eval(Container.DataItem,"Staus") %>></asp:Label></td>
                                        <td style="width: 200px; border-right: #e8e8e8 1px solid;" align="center">
                                       
                                        <asp:Label ID="Label4" runat="server" Style="position: relative" Text=<%#DataBinder.Eval(Container.DataItem,"CompleteDate") %>></asp:Label></td>
                                        <td style="width: 200px; border-right: #e8e8e8 1px solid;" align="center">
                                       
                                        <asp:Label ID="Label5" runat="server" Style="position: relative" Text=<%#DataBinder.Eval(Container.DataItem,"Remark") %>></asp:Label></td>
                                    <td style="width: 50px; border-bottom: #e8e8e8 1px solid;"  align="right">
                                       
                                        <div style="left: 2px; width: 150px; position: relative; height: 25px;
                                            text-align: right">
                                            <asp:Button ID="Button6" runat="server" Style="position: relative" Text="修改" OnClick="Button6_Click"  OnCommand="Button6_Command"  CommandArgument='<%#DataBinder.Eval(Container.DataItem,"ID")%>'/>
                               
                                            <img
                                            alt="a"  src="images/delete.gif" style="border-top-style: none; border-right-style: none;
                                                    border-left-style: none; position: relative; border-bottom-style: none; top: 5px;" />
                                            <asp:LinkButton ID="lbtnDelete" runat="server"
                                                OnCommand="lbtnDelete_Command" Style="position: relative"  CommandArgument='<%#DataBinder.Eval(Container.DataItem,"ID")%>'>删除</asp:LinkButton>&nbsp;
                                             </div>
                                    </td>
                                   
                                    <script type="text/jscript">
                                    function airport(c){
                                    c.style.color="#220000";   
                                       }
                                    function airporthover(c){
                                    c.style.color="#666666";
   
                                     }
                                    </script>
                                </tr>
                              
                            </table>
                           <div>
                           </div>
                           &nbsp;
                        </ItemTemplate>
                        <SeparatorTemplate>
                            <br />                           
                        </SeparatorTemplate>
                    </asp:DataList></td>
            </tr>
            <tr>
                <td align="right">
                    共<asp:Label ID="lblMesTotal" runat="server" Style="position: relative" Text="Label"></asp:Label>条记录&nbsp;
                    第<asp:Label ID="lblPageCur" runat="server" Style="position: relative" Text="Label"></asp:Label>页&nbsp;
                    共<asp:Label ID="lblPageTotal" runat="server" Style="position: relative" Text="Label"></asp:Label>页&nbsp;
                    <img src="images/reply.gif" style="position: relative; top: 2px;" />
                                            <a href="add.aspx" target="_blank">添加</a>
                    <asp:Button ID="Button3" runat="server" Style="position: relative" Text="首页" OnClick="Button3_Click" />
                    <asp:Button ID="Button1" runat="server" Style="position: relative" Text="上一页" OnClick="Button1_Click" />
                    <asp:Button ID="Button2" runat="server" Style="position: relative" Text="下一页" OnClick="Button2_Click" />
                    <asp:Button ID="Button4" runat="server" Style="position: relative" Text="尾页" OnClick="Button4_Click" />
                    &nbsp; 转到<asp:DropDownList ID="DropDownList1" runat="server"
                        Style="position: relative">
                    </asp:DropDownList>&nbsp;
                    <asp:Button ID="Button5" runat="server" Style="position: relative" Text="GO" OnClick="Button5_Click" /></td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

 

 

 

Default.cs的内容:

 

using System;
using System.Data;
using System.Configuration;
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
{
    string curPage;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.lblPageCur.Text = "1";
            dataGridBind();           
        }   
    }
    public void dataGridBind()
    {       
        curPage =this.lblPageCur.Text;
        SqlConnection conn = DB.createCon();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "select * from Prjinfo order by ID ";
        cmd.Connection = conn;
        SqlDataAdapter sda = new SqlDataAdapter();
        sda.SelectCommand = cmd;
        DataSet ds = new DataSet();
        sda.Fill(ds, "Prjinfo");
        PagedDataSource pds = new PagedDataSource();
        pds.AllowPaging = true;
        pds.PageSize =5;
        pds.DataSource = ds.Tables["Prjinfo"].DefaultView;
        pds.CurrentPageIndex = Convert.ToInt32(curPage) - 1;
        this.lblPageTotal.Text = pds.PageCount.ToString();
        this.Button1.Enabled=true;
        this.Button2.Enabled=true;
        if (curPage == "1")
        {
            this.Button1.Enabled = false;
        }           
        if (curPage == pds.PageCount.ToString())
        {
            this.Button2.Enabled = false;
        }
        this.DataList1.DataSource = pds;
        this.DataList1.DataBind();

        cmd.CommandText = "select count(*) from Prjinfo";
        this.lblMesTotal.Text = Convert.ToString(cmd.ExecuteScalar());
        if (!IsPostBack)
        {
            int a = pds.PageCount;
            for (int i = 1; i <= a; i++)
            {
                this.DropDownList1.Items.Add(i.ToString());
            }
        }
    }

    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        LinkButton dele=(LinkButton)(e.Item.FindControl("lbtnDelete"));
        if (dele != null)
        {
            dele.Attributes.Add("onclick","return confirm('确定删除吗?')");
        }
    }

    protected void lbtnDelete_Command(object sender, CommandEventArgs e)
    {
       
            string userID = e.CommandArgument.ToString();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = DB.createCon();
            cmd.CommandText = "delete from Prjinfo where ID="+userID+"";
            if (cmd.ExecuteNonQuery() > 0)
            {
                Response.Write("<script>alert('删除成功!');window.location=window.location;</script>");
            }
            else
            {
                Response.Write("<script>alert('删除失败!');window.location=window.location;</script>");
            }
       
    }


    protected void Button6_Command(object sender, CommandEventArgs e)
    {
        string username;
        string testID = e.CommandArgument.ToString();
        Response.Redirect("change.aspx?username="+testID+"");

    }
   


    protected void Button1_Click(object sender, EventArgs e)
    {
        this.lblPageCur.Text = Convert.ToString(Convert.ToInt32(this.lblPageCur.Text)-1);
        dataGridBind();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        this.lblPageCur.Text = Convert.ToString(Convert.ToInt32(this.lblPageCur.Text) + 1);
        dataGridBind();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        this.lblPageCur.Text = "1";
        dataGridBind();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        this.lblPageCur.Text = this.lblPageTotal.Text;
        dataGridBind();
    }
    protected void Button5_Click(object sender, EventArgs e)
    {   
            this.lblPageCur.Text = this.DropDownList1.SelectedValue;
            dataGridBind();
    }

    protected void Button6_Click(object sender, EventArgs e)
    {
        Response.Write("<script>location.href='change.aspx';</script>");
        dataGridBind();
    }
}

 

 

 

说明:在default.aspx中插入了js关于背景切换的代码。另一重点在与数据绑定以及dropdownlist控件的使用和页面的跳转。

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值