• 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>

  • 相关阅读:
    redis客户端windows版中文乱码解决方案
    nginx做负载均衡,怎么在有宕机情况出现时保证网站的响应速度
    支付宝同步和异步验签结果不一致的解决方法
    @ResponseBody中文乱码解决方案
    [javamail]AUTH LOGIN failed;Invalid username or password报错
    Could not load driverClass ${driverClassName} 的解决方案
    eclipse中,maven报错maven.multiModuleProjectDirectory system property is not set
    spring bean初始化和销毁方法
    关于静态资源是否应该放到WEB-INF目录
    使用Jedis出现Connection refused的解决方案
  • 原文地址:https://www.cnblogs.com/cf924823/p/5065712.html
Copyright © 2020-2023  润新知