zoukankan      html  css  js  c++  java
  • 12.22 repeater 主页

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class Main : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    if (Session["uid"] != null)//如果数据库有数据跳转到主界面
    {
    if (!IsPostBack)//判断是否刷新
    {

    InfoDataContext context = new InfoDataContext();

    //指定数据源
    Repeater1.DataSource = context.Info;
    Repeater1.DataBind();


    }
    }
    else//如果没有数据 发回到等录界面
    {
    Response.Redirect("denglu.aspx");
    }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    //按照代号和姓名查询
    //取所有数据
    InfoDataContext context = new InfoDataContext();
    List<Info> list= context.Info.ToList();

    //取第一个查询条件
    string code=txtCode.Text;
    if( code!="")
    {
    list=list.Where(p=>p.Code==code).ToList();
    }
    //取第二个查询条件
    string name=txtName.Text;
    if( name!="")
    {
    list = list.Where(p => p.Name.Contains(name)).ToList();
    }

    //给repeater做数据源
    Repeater1.DataSource = list;
    Repeater1.DataBind();


    }
    //造显示性别函数
    public string ShowSex()
    {
    return Convert.ToBoolean(Eval("Sex"))?"男":"女";

    }
    //造显示民族的函数
    public string ShowNation()
    {

    InfoDataContext context = new InfoDataContext();

    string code= Eval("Nation").ToString();


    return context.Nation.Where(p=>p.Code==code).First().Name;


    }
    //造显示生日的函数
    public string ShowBirthday()
    {
    return Convert.ToDateTime(Eval("Birthday")).ToString("yyyy年MM月dd日");

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
    Response.Redirect("Insert.aspx");
    }
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

    }
    }

     

    <h1 > 主界面</h1>

    <asp:Label ID="Label1" runat="server" Text="代号:"></asp:Label>
    &nbsp;<asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
    <asp:Label ID="Label2" runat="server" Text="姓名:"></asp:Label>
    &nbsp;
    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="查询" />
    &nbsp;&nbsp;
    <asp:Button ID="Button2" runat="server" Text="添加 " OnClick="Button2_Click" />


    <asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
    <HeaderTemplate>
    <table width="800" border="0" cellspacing="1" cellpadding="1" bgcolor="#6600FF">
    <tr>
    <td width="120" height="30" align="center" valign="middle" bgcolor="#FFFFFF">代号</td>
    <td width="120" align="center" valign="middle" bgcolor="#FFFFFF"> 姓名</td>
    <td width="120" align="center" valign="middle" bgcolor="#FFFFFF">性别</td>
    <td width="120" align="center" valign="middle" bgcolor="#FFFFFF"> 名族</td>
    <td width="100" align="center" valign="middle" bgcolor="#FFFFFF">生日</td>
    <td width="100" align="center" valign="middle" bgcolor="#FFFFFF">操作</td>
    </tr>
    </HeaderTemplate>


    <ItemTemplate>

    <tr bgcolor="#FFFFFF">
    <td width="120" height="30" align="center" valign="middle"><%#Eval("Code") %></td>
    <td width="120" align="center" valign="middle" ><%#Eval("Name") %></td>
    <td width="120" align="center" valign="middle" ><%# ShowSex()%></td>
    <td width="120" align="center" valign="middle" ><%#ShowNation() %></td>
    <td class="kc" width="100" align="center" valign="middle" ><%#ShowBirthday() %></td>
    <td width="100" align="center" valign="middle" ><a href="Delete.aspx?code=<%#Eval("Code") %>">删除</a>&nbsp;<a href="Update.aspx?code=<%#Eval("Code") %>">修改</a></td>
    </tr>
    </ItemTemplate>
    <FooterTemplate></table></FooterTemplate>
    </asp:Repeater>
    &nbsp;</p>

  • 相关阅读:
    lombok-@Accessors注解
    spring boot 当参数传入开头多个0时,报错:JSON parse error: Invalid numeric value: Leading zeroes not allowed
    linux查看历史操作记录并且显示执行时间
    IDEA中mybatis插件自动生成手写sql的xml文件
    CPU核数和load average的关系
    Jenkins--Credentials添加证书从git上拉代码
    解决输入git branch 进入编辑状态,mac下出现END,无法返回
    Git log和git reflog
    SpringCloud入门之常用的配置文件 application.yml和 bootstrap.yml区别
    springboot定时任务
  • 原文地址:https://www.cnblogs.com/cf924823/p/5065712.html
Copyright © 2011-2022 走看看